+ 3

I have to write 2 times for it to read.

My problem is with the "read.next()" it works fine but I have to write 2 times yes for it to read and execute the loop again. How do I fix this System.out.println("Any last changes ? (Yes or No)"); newyn = read.next(); } while ((newyn.equals("Yes")) || (newyn.equals("yes"))); Heres a print : https://prntscr.com/ijx7zp Full code : https://code.sololearn.com/csOP75dVT5qq/#java

26th Feb 2018, 12:59 PM
Leonardo Rodrigues
Leonardo Rodrigues - avatar
2 Réponses
+ 2
If I were you, I'd replace "do" on line 49 with "while( true )" and add an "if" statement in the end of the loop, line 108: if ((newyn.equals("Yes")) || (newyn.equals("yes"))) continue; else break; } Besides, you might want to get the code on lines 50 and 51 out of the loop, so you won't be forced to input the string both in the end and in the beginning. Let the "while" statement execute only if user wants to change anything.
26th Feb 2018, 1:19 PM
Михаил «Sarf» Дружинин
Михаил «Sarf» Дружинин - avatar
0
Thanks a lot that resolved my problem and my program is working just as I wanted.
26th Feb 2018, 3:07 PM
Leonardo Rodrigues
Leonardo Rodrigues - avatar