Hello I know this is so basic but I am having trouble in comparing char specifically with the !=. Whenever I input other letter (not y and n) code still loop.
I tried changing the != to == and when i press Y it gets out of loop.
How is this happening? Thank you!
public static void main(String[] args) { char inputChar; Scanner input = new Scanner(System.in); do { System.out.println("-----------------------------------------------"); System.out.println("Try Again(Y/N)? "); do { inputChar = input.next().toUpperCase().charAt(0); System.out.println("Loop"); } while (inputChar != 'Y' || inputChar != 'N'); System.out.println(inputChar + " d"); } while (inputChar == 'Y'); System.out.println("Thank you and Good bye!"); }
inputChar != 'Y' || inputChar != 'N'this is always true so you'll never exit that loop. Use&&instead