Да, в этом вопросе много дубликатов, я знаю.
Следующий код не имеет проблем с компиляцией в BlueJ, однако при запуске в Eclipse я получаю сообщение об ошибке в следующей строке:
while (selection != 'Q' && selection != 'q');
Ошибка: selection
не может быть решенак переменной.
Почему я испытываю эту ошибку в Eclipse, а не в BlueJ?
public class menuMain {
public menuMain(String args) {
System.out.println("Welcome to the Project");
Scanner in = new Scanner(System.in);
do {
showMenu();
String menu = in.nextLine(); // read a line of input
char selection;
if (menu.length() > 0) {
selection = menu.toLowerCase().charAt(0); // extract the first char of the line read
}
else {
System.out.println("invalid input:\t"+selection);
System.out.println("Press enter to continue...");
Scanner itScan = new Scanner(System.in);
String nextIt = itScan.nextLine();
}
switch (selection)
{
case 'a':
changeTime time = new changeTime ();
break;
case 'b':
watchTime timeStop = new watchTime();
break;
case 'q':
System.out.println("\nEnding Now\n");
System.exit(0);
break;
default:
System.out.println("Instruction is invalid");
}
}
while (selection != 'Q' && selection != 'q');
System.exit(0);
}
}