+ 1

error: variable answer might not have been initialized }while(answer == "Y"); \\ the error pointed at >a. HELP

System.out.printf("Do you want to look on another Account? (Y/N)"); answer = input.next(); if(answer == "N") System.out.printf("Thank you, the program will exit now, Goodbye"); } } }while(answer == "Y");

19th May 2021, 7:38 PM
Owen Ong
Owen Ong - avatar
3 Respuestas
+ 3
Initialize 'answer variable first' as String answer; Also answer=="N" not work in Java. == Used for refference comparision of strings. Use answer.equals("N") instead of (answer=="N") for string comparisions...
19th May 2021, 7:52 PM
Jayakrishna 🇮🇳
+ 1
Got it, Thanks
19th May 2021, 8:24 PM
Owen Ong
Owen Ong - avatar
0
You're welcome...
20th May 2021, 5:37 PM
Jayakrishna 🇮🇳