实例1
public class Day04_Score_Test { public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); int a =input.nextInt(); //判断输入的分数是什么等级 //将下面的语句改写成嵌套的 if else 语句 if (a < 0 || a > 100 ){ System.out.println("您的分数不符合规范"); }else if (a > 90){ System.out.println("优秀"); }else if (a > 80){ System.out.println("良好"); }else if (a > 60){ System.out.println("及格"); }else { System.out.println("不及格"); } } }
事例2
public static void main(String[] args){
//从键盘输入一个年份,和月份
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.print("年份:");
int year = input.nextInt();
System.out.print("月份:");
int month = input.nextInt();
if(year>0){
if(month>=1 && month<=12){
//合法的情况
int days;
if(month==2){
if(year%4==0 && year%100!=0 || year%400==0){
days = 29;
}else{
days = 28;
}
}else if(month==4 || month==6 || month==9 || month==11){
days = 30;
}else{
days = 31;
}
System.out.println(year+"年" + month + "月有" + days +"天");
}else{
System.out.println("月份输入不合法");
}
}else{
System.out.println("年份输入不合法");
}
}