I created a while-loop to create a menu for my program, it will keep looping until the user types 'Quit' into the console. My problem is that whenever I enter 'Transfer' into the console the if statement runs perfectly but when it goes back to the start of the loop the System.out.println(); message prints twice instead of once. This doesn't happen with any of the other options.
Code:
int x = 0;
while(x != 1) {
System.out.println("To transfer funds, please type 'Transfer'\n" //Typical message
+ "To list recent transactions, please type 'Recent'\n"
+ "To display account details, please type 'Details'\n"
+ "To quit the application, please type 'Quit'");
String Option1 = "Transfer"; //Variables
String Option2 = "Recent";
String Option3 = "Details";
String Option4 = "Quit";
String Menu = ConsoleInput.nextLine();
if (Menu.equals(Option1)) {
//Statements
} else if(Menu.equals(Option2)){
//Statements
} else if(Menu.equals(Option3)){
//Statements
} else if(Menu.equals(Option4)){
//End statement
x++;
}
}
Aucun commentaire:
Enregistrer un commentaire