java條件陳述式練習題

來源:互聯網
上載者:User

標籤:語句   最大   image   next   9.png   技術   scanner   身高   else   

輸入三個數字顯示最大的:

System.out.println("請輸入三個數字:");
int a,b,c;
Scanner d = new Scanner(System.in);
a= Integer.parseInt(d.nextLine());
b= Integer.parseInt(d.nextLine());
c= Integer.parseInt(d.nextLine());

if(a>b&&a>c){

System.out.println(a);
}
else if(b>a&&b>c){

System.out.println(b);
}
else if(c>a&&c>b){
System.out.println(c);
}

 

輸入一個年份判斷是不是閏年

System.out.println("請輸入年份:");
int a;
Scanner b= new Scanner(System.in);
a=Integer.parseInt(b.nextLine());
if(a%400==0&&a%100!=0||a%4==0){
System.out.println("是閏年");
}
else{
System.out.println("不是閏年");
}

 

輸入性別、身高、體重 判斷是不是標準體重(男性標準體重:身高-體重=100±3,女性標準體重:身高-體重=110±3)

System.out.println("請輸入性別、身高、體重");
int g,t;
String x;
Scanner b = new Scanner(System.in);
x=b.nextLine();
g = b.nextInt();
t = b.nextInt();
if(x.equals("男")){
if(g-t>=97&&g-t<=103){

System.out.println("標準體重");
}
else if(g-t>97){
System.out.println("偏瘦");
}
else if(g-t<103){
System.out.println("偏胖");
}
}
else if(x.equals("女")){
if(g-t>=107&&g-t<=113){

System.out.println("標準體重");
}
else if(g-t>107){
System.out.println("偏瘦");
}
else if(g-t<113){
System.out.println("偏胖");
}
}

 

 

java條件陳述式練習題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.