Reputation: 9
I Wrote this code to ask the user if he wants to add money to his account , and I made a do while loop to read the input if it is ("oui" or "non") and I made the variable rep to read the input from the user , Error : rep can not be resolved !
do {
System.out.println("Souhaitez vous ajoutez de l'argent ?");
String rep = sc.nextLine();
} while (!rep.equals("Oui") || !rep.equals("Non"));
Upvotes: 1
Views: 50
Reputation: 5004
You have to declare rep outside of the loop put this
String rep;
Above your loop and then inside do
rep = sc.nextLine();
In Java you can only once declare a variable with a type
String rep = "3";
String rep = "5";
Will lead to an compiler error Duplicate local variable rep and in your loop you are doing this. The other point is when you declare it inside the loop the while in the outer scope can not resolve it rep cannot be resolved.
Upvotes: 1