由于某种原因,我的代码无法运行,说我有一些错误。
//ask for user input for the selected vehicle
if(choice == 'A' || 'a') {
System.out.println("How many miles would you like to drive the van?: ");
milesDriven = input.nextInt();
} else if(choice == 'B' || 'b') {
System.out.println("How many miles would you like to drive the honda?: ");
milesDriven = input.nextInt();
} else if(choice == 'C' || 'c') {
System.out.println("Here are the statuses of your cars!\n");
Garage.printCarStatus();
} else {
System.out.println("That is an invalid choice!");
}
最佳答案
更改代码中的条件 -
if(choice == 'A' || 'a') // the OR operation is not applicable of char values
到
if(choice == 'A' || choice == 'a') // boolean operands using OR
关于java - 该程序的 if else 语句有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46461753/