Okay, so I have a relatively simple program. All it does is check to see if the letters 'Q' or 'q' is typed into an input. If it is, the program terminates... if not, the program keeps continuing until 'Q' or 'q' is entered in.
I tried using an "if" statement coupled with a "break" and that seems to work inside of the "while" loop... except, I want this program to work with using the "break"... if you know what I mean... Here's the sample code below...
As of right now... The program compiles and builds correctly... but everytime I execute in the Eclipse Console, anything I enter doesn't seem to terminate the program, even if I type in 'Q' or 'q'. This is weird because whenever I put in "while(choice != 'Q')" or "while(choice != 'q')" it seems to work (when I type the respective keys)... but not when I put it together and connect it with a conditional 'OR'...Code:import java.util.Scanner; class testclass { public static void main(String args[]) { char choice; Scanner myScanner = new Scanner(System.in); System.out.print("Type Q to Quit: "); choice = myScanner.findInLine(".").charAt(0); System.out.print("\n"); while((choice != 'Q') || (choice != 'q')) { System.out.print("Type Q to Quit: "); choice = myScanner.findInLine(".").charAt(0); System.out.print("\n"); } } }
Anyone know why this happens and how to fix this?


LinkBack URL
About LinkBacks




Reply With Quote








Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum