When 'y' or 'Y' is inputted, I want the code to the prompt System.out.print("Y/y or N/n: "); starting from the first do,but instead the code will prompt System.out.print("bad answer, try again: ");, and I only want char besides y,Y,n,N to be the case.
The only code that follows is when 'n' or 'N' is entered, following System.exit(0);
import java.util.Scanner;
public class Test
{
public static void main(String[] args)
{
Scanner kb = new Scanner(System.in);
char ch;
do
{
System.out.print("Y/y or N/n: ");
do
{
ch = kb.nextLine().charAt(0);
if (ch == 'n' || ch == 'N')
{
System.exit(0);
}
else if (ch != 'y' || ch != 'Y' || ch != 'n' || ch != 'N');
{
System.out.print("bad answer, try again: ");
}
}
while (ch != 'y' || ch != 'Y' || ch != 'n' || ch != 'N');
}
while (ch == 'y' || ch == 'Y');
}
}
&&instead of||.