import java.util.Scanner;
public class ticket{
public static void main(String[] args) {
Scanner myScanner = new Scanner(System.in);// 创建一个scanner对象
System.out.println("输入月份");
int month = myScanner.nextInt();//创建月份输入
System.out.println("输入年龄");
int age = myScanner.nextInt();//创建年龄输入
if(month >= 4 && month <= 10 ){ // 设定旺季区间
if (age >= 18 && age <= 60){ //成人
System.out.println("成人\t"+"票价为60");
} else if (age < 18){ //儿童
System.out.println("儿童\t"+"票价为30");
} else {//老人
System.out.println("老人\t"+"票价为20"); }
} else if (month < 4 && month >10 ) { //淡季
if(age >= 18 && age <= 60){ // 成人
System.out.println("成人\t"+"票价为40");
} else { //其他
System.out.println("票价为20");}
} else if (month > 12 && month < 0 && age < 0 ){
//限定月份小于12,以及年龄月份大于零
System.out.println("输入错误");
} else {
System.out.println("请重新输入"); //不知道为什么输入范围外的值会只输出“请重新输入”,希望有知道的小伙告知一下
}
}
}
else if (month < 4 && month >10 )
--你自己看看这个if条件能满足吗?应该是
else if (month < 4 || month >10 )
另外 else if (month > 12 && month < 0 && age < 0 ) 也是一样的问题,矛盾的条件,&&是不会满足的
而且你这两个else之间条件也是有重合部分,应该交换一下顺序,否则后面这个else if是不会执行的
不要怀疑是计算机的问题,这是你的问题,你的主if的条件肯定是false的