|
||||||
| Java Help Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Simple Program - Use of "OR" in While Loops
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... 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? |
|
|||
|
Re: Simple Program - Use of "OR" in While Loops
Oh man...... I can't believe something like that slipped my mind =_=;;;;
Makes me feel uber stupid right now... Thanks a lot. That solved my problem *sigh* hahaha |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [HELP] C++ program that will ask the user to enter not greater than to 15 numbers | Kyram143 | C and C++ | 8 | 12-16-2009 02:53 PM |
| Tutorial: Starting C# with C# 2008 Express Edition | Jordan | CSharp Tutorials | 20 | 07-27-2009 05:45 AM |
| Debugging a C++/C File with GDB Debugger | awesome001 | C and C++ | 2 | 01-01-2009 08:07 PM |
| Creating simple Notition store program | Coldhearth | Java Help | 1 | 12-10-2008 04:44 PM |
| Fairly Simple Program Request | Fodder | MarketPlace | 4 | 12-22-2007 12:20 AM |
All times are GMT -5. The time now is 11:40 PM.
Amrosama.cc
Arekbulski.cc
Debtboy.cc
Guest.cc
Jaan.cc
James.cc
Mathx.cc
Tsz.cc
Vswe.cc