This question already has an answer here:
- Issue with logic and Loop in Java 4 answers
My program creates an array and asks the user whether he wants to sort it or not by entering 'Y' or 'N'. When I enter anything as the input, it still says "Invalid Input"..
Code:
do{
System.out.println ("Do you want to sort your array? (Y/N)");
System.out.print ("> ");
ch = br.readLine().toUpperCase();
if(!ch.equals('N')||!ch.equals("Y")) System.out.println("Invalid Entry. Please Enter 'Y' or 'N'");
else break;
}while(true);
if(ch.equals("N"))
{
System.out.println("Thank You.");
return;
}
OUTPUT:
Do you want to sort your array? (Y/N)
Y
Invalid Entry. Please Enter 'Y' or 'N'
Do you want to sort your array? (Y/N)
Aucun commentaire:
Enregistrer un commentaire