Я пытаюсь сделать цикл, который считывает и обрабатывает предложения и заканчивается только тогда, когда пользователь набирает «Остановить», чтобы завершить программу. Ниже приведен код им с помощью и я получаю ошибку компиляции else if
Выполнение цикла до тех пор, пока пользовательские типы в «Стоп»
System.out.println("Please Input a sentence and (terminate with \"STOP \")");
String sentenceInput;
int sentenceLength;
char sentencePunct;
int divisionNum;
int number;
int divided;
int remainder;
sentenceInput= myScanner.nextLine();
sentenceLength = sentenceInput.length();
remainder = sentenceLength%2;
sentencePunct = sentenceInput.charAt(sentenceLength -1);
while (!sentenceInput.equals ("STOP")) {
if (sentencePunct == '?')
{
if (remainder == 0)
System.out.println("Yes");`
System.out.println("Please Input another sentence (terminate with \"STOP \")");
sentenceInput= myScanner.nextLine();
else
System.out.println("No");
System.out.println("Please Input another sentence (terminate with \"STOP \")");
sentenceInput= myScanner.nextLine();
}
else if (sentencePunct == '!')
System.out.println("Wow!");
System.out.println("Please Input another sentence (terminate with \"STOP \")");
sentenceInput= myScanner.nextLine();
else
System.out.println("You always say " + sentenceInput);
System.out.println("Please Input another sentence (terminate with \"STOP \")");
sentenceInput= myScanner.nextLine();
}
}
Можете ли вы отправить сообщение об ошибке компилятора? – digitalextremist
Я решил проблему, спасибо, что ошибка компиляции была «else without if» –