New to programming and just started Java. I am unable to get the != operand to work with char.This is with regards to the while loop.even though the correct input is being placed. The loop keeps saying, it is an invalid input, despite the correct input being placed.
Input is correctly recognised and is converted to upper case. But the while loop is not working. Any suggestions would be appreciated thanks!
Scanner keyboard = new Scanner(System.in); //Create object to read user data
System.out.println("Please enter your age between 1 - 110");
age = keyboard.nextInt();
while((age < 1) || (age > 110)){
System.out.println("Error please input a valid age");
System.out.println("");
System.out.println("Please enter your age between 1 - 110");
age = keyboard.nextInt();
}
System.out.println("Please enter this person's gender (M/F)");
gender = keyboard.next().charAt(0);
gender = Character.toUpperCase(gender); // Convert all inputted character to upper case
while((gender != 'M') || (gender != 'F')){
System.out.println("Error please input a valid gender");
System.out.println("");
System.out.println("Please enter this person's gender (M/F)");
gender = keyboard.next().charAt(0);
gender = Character.toUpperCase(gender); // Convert all inputted character to upper case
}
System.out.println("Please enter whether this person watches the show regularly (Y/N");
show = keyboard.next().charAt(0);
show = Character.toUpperCase(show); // Convert show to upper case
while((show != 'Y') || (show != 'N')){
System.out.println("Error - input invalid");
System.out.println("");
System.out.println("Please enter whether this person watches the show regularly (Y/N");
show = keyboard.next().charAt(0);
show = Character.toUpperCase(show); // Convert show to upper case
}
System.out.println("Do you want to enter another person's details (Y/N)?");
details = keyboard.next().charAt(0);
details = Character.toUpperCase(details);
while((details != 'Y') || (details != 'N')){
System.out.println("Error - Invalid input");
System.out.println("");
System.out.println("Do you want to enter another person's details (Y/N)?");
details = keyboard.next().charAt(0);
details = Character.toUpperCase(details);
}