java programming loop problem
my problem is when i type NN to this code it ends my program..but i want that is i type more than one char it reloops again..
help please thank you
Code :
do{
System.out.print("\nDo You Want To Try Again? [Y/N]? ");
input = scan.next();
if(input.charAt(0) == 'n' || input.charAt(0) == 'N')
{
System.exit(0);
}
}while(!(input.charAt(0) == 'y' || input.charAt(0) == 'Y' || input.length() >= 2));
}while(input.charAt(0) == 'y' || input.charAt(0) == 'Y' );
}
}
Re: java programming loop problem
Quote:
if(input.charAt(0) == 'n' || input.charAt(0) == 'N')
You are only checking the first character to == n or N. If you want to check something else you will have to check something else then. How would you check if more than one character was entered?
Re: java programming loop problem
Re: java programming loop problem
Well what else do you want to check for? There are multiple ways to do this. The point of the assignment is for you to choose a way that will work. Once you know how to do it, then write the code. If you can not get it tell us which way you chose and where you are stuck.