java - Ttrying to loop until user types in "Stop" -
i try loop reads , processes sentences , ends when user types "stop" end program. below code im using , keep getting compile error else if
system.out.println("please input sentence , (terminate \"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 sentence (terminate \"stop \")"); sentenceinput= myscanner.nextline(); else system.out.println("no"); system.out.println("please input sentence (terminate \"stop \")"); sentenceinput= myscanner.nextline(); } else if (sentencepunct == '!') system.out.println("wow!"); system.out.println("please input sentence (terminate \"stop \")"); sentenceinput= myscanner.nextline(); else system.out.println("you " + sentenceinput); system.out.println("please input sentence (terminate \"stop \")"); sentenceinput= myscanner.nextline(); } }
your scope screwed on place, need make sure complete if/else enclosed {}, of else's don't have connect to.
while (!sentenceinput.equals ("stop")) { if (sentencepunct == '?') { if (remainder == 0) { system.out.println("yes");` system.out.println("please input sentence (terminate \"stop \")"); sentenceinput= myscanner.nextline(); } else { system.out.println("no"); system.out.println("please input sentence (terminate \"stop \")"); sentenceinput= myscanner.nextline(); } } else if (sentencepunct == '!') { system.out.println("wow!"); system.out.println("please input sentence (terminate \"stop \")"); sentenceinput= myscanner.nextline(); } else { system.out.println("you " + sentenceinput); system.out.println("please input sentence (terminate \"stop \")"); sentenceinput= myscanner.nextline(); } }
}
Comments
Post a Comment