1.三个和尚(三个和尚取最大值)
public static void main(String[] args) {
int height1,height2,height3;
Scanner sc = new Scanner(System.in);
System.out.println("请输入第一个和尚身高:");
height1 = sc.nextInt();
System.out.println("请输入第二个和尚身高:");
height2 = sc.nextInt();
System.out.println("请输入第三个和尚身高:");
height3 = sc.nextInt();
int height;
height = height1 > height2 ? height1 : height2;
height = height > height3 ? height : height3;
System.out.println("三个和尚最大身高是:"+height+"cm“);
}
2.考试奖励(if-else)
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("请输入小明的考试成绩:");
int score = sc.nextInt();
if(score >100 || score < 0){
System.out.println("您输入的数据有错");
}else if(score >= 95){
System.out.println("小明的礼物是山地自行车");
}else if(score >= 90){
System.out.println("小明的礼物是去游乐场玩一次");
}else if(score >= 80){
System.out.println("小明的礼物是变形金刚");
}else{
System.out.println("小明的礼物是胖揍一顿");
}
}
3.春夏秋冬
import java.util.Scanner;
public class Season {
public static void main(String[] args) {
/*
* 一年有四个季节,春夏秋冬,根据输入值判断是什么季节
* 3,4,5春季;6,7,8夏季;9,10,11秋季;1,2,12冬季
*/
Scanner sc = new Scanner(System.in);
System.out.println("请输入月份(1-12):");
int month = sc.nextInt();
switch(month){
case 1:
case 2:
case 12:
System.out.println("您输入的是冬季");
break;
case 3:
case 4:
case 5:
System.out.println("您输入的是春季");
break;
case 6:
case 7:
case 8:
System.out.println("您输入的是夏季");
break;
case 9:
case 10:
case 11:
System.out.println("您输入的是秋季");
break;
default:
System.out.println("您输入的月份有误");
break;
}
}
}
原文:https://www.cnblogs.com/wazl/p/11416123.html