为什么判断语句写成加粗部分这样不能运行?从语法上来说,这样写错了吗?不能写区间吗?
int age=25;
if(age>60){
System.out.println("老年");
}else if (40<=age<=60){
System.out.println("中年");
}else if(18<=age){
System.out.println("少年");
}else{
System.out.println("同年");
}
对,不能写区间,只能写age <= 60 && age >= 40
对,和数学还是有区别的,只能是age >= 40 && age <=60