Why doesn't my while loop end?

* Main method
public static void main(String args[])
Scanner sc = new Scanner(System.in);
//get input
String hexa = "nothing";
while (hexa != "q")
System.out.println("");
System.out.println("Please enter a hexadecimal to convert to binary, enter q to quit");
hexa = sc.next();
int hexlength = hexa.length();
for (int i = 0; i < hexlength; i ++)
char hexadec = hexa.charAt(i);
//send to subprogram
findBinary(hexadec, hexlength);
why doesn't my while loop end when i enter q?

The equals method returns a boolean (true/false). So you simply negate the returned value.
if( ! methodCall()) {
}

Similar Messages

  • Do while loop doesn't end

    my do while loop does not exits can help?
    do{
                   a++;
                   System.out.print("Enter account number "+a+" (Press ENTER to exit) : ");
                   account=CspInput.readString();
                   item[a-1] = account;
                   System.out.print("Enter credit card expenses for "+account+" : $");
                   price=CspInput.readDouble();
                   amount[a-1]= price;
                   System.out.println("");
                   if((a-1)==0)
                        summaryByMonth[i-1]=item[a-1]+"\t\t"+fmt.format(amount[a-1])+"\n";
                   else
                        summaryByMonth[i-1]+=item[a-1]+"\t\t"+fmt.format(amount[a-1])+"\n";
                   totalAmount[i-1]+=amount[a-1];
              }while(account != null && account != " ");

    si0ngch33 wrote:
    my do while loop does not exits can help?
    do{
                   a++;
                   System.out.print("Enter account number "+a+" (Press ENTER to exit) : ");
                   account=CspInput.readString();
                   item[a-1] = account;
                   System.out.print("Enter credit card expenses for "+account+" : $");
                   price=CspInput.readDouble();
                   amount[a-1]= price;
                   System.out.println("");
                   if((a-1)==0)
                        summaryByMonth[i-1]=item[a-1]+"\t\t"+fmt.format(amount[a-1])+"\n";
                   else
                        summaryByMonth[i-1]+=item[a-1]+"\t\t"+fmt.format(amount[a-1])+"\n";
                   totalAmount[i-1]+=amount[a-1];
              }while(account != null && account != " ");Either use a debugger or put some print statements in the loop to see what the actual value of account is:
    Example:
    do{
        //... bunch of code
        System.out.println("DEBUGGING - account is '"+account+"'");
    }while(account != null && !account.equals(" "));

  • Why does while loop pause during operation

    Hi everyone,
    I have written the attached code which will eventually be a part of a bigger program. The program is intended to log some test value, in this case just the date and time  to a csv file  when a button is pressed (log in WHITE, loop1).  Loop2 is intended to read a test value from a line in the first csv file and then add an extra test value to the end of that line when the serial number matches and then saves that line to a new csv file. This all works well but loop2 seems to pause a few times before continuing when either of the log button is pressed. I tried putting the code in 1 while loop with no success. Can anybody see what I am doing wrong?
    Attachments:
    ResinV10_csv.vi ‏25 KB

    Maiz wrote:
    Can anybody see what I am doing wrong?
    In addition to waht has been said already, your code is extremely convoluted.
    How often does the "read" file change? Do you really need to read the entire file with thousands of rows every ms just to look at one row?. If the file never changes, you could read it once before the loop.
    The way do do array opearions is mind boggling. You take one row, Index out the first element twice in parallel (once is enough!), then you index out the first element, built it into an array of one element, and compare that array with a scalar. Would't comparing the orignal element with the scalar be equivalent?
    Index array is resizable, you only need one instance.
    Getting five elements in a row just to build them back into a 1D array seems rather pointless. If the array has only five elements, there is nothing to do, and if it has more elements, you cold use "array subset", and if it has fewer elements, use "reshape array" to size 5.
    The correct format for reading strings is %s (not %.10f).
    Since you want both loops to run at the same speed, why don't you put it all in one loop? (this even eliminates the local variable) Then you could use a parallel loop for the file saving, using queues in order not to slow down the main loop. In the parallel loop, open the files before the loop, use lowlevel writes inside the loop, and close the files once the program stops.
    Can you explain your setup and what the program is supposed to do? I am sure it could be done with 20% of the current code.
    LabVIEW Champion . Do more with less code and in less time .

  • Why doesn't the volume control settings allow a greater range (on the low end)?

    Maybe my ears are really sensitive, but for every iphone I've had, the lowest volume is not low enough.  My phone is often louder than I want in my headphones even at the lowest setting.  I find myself trying to lower the volume but ending up in silence.  After putting it back up to the lowest setting, I end up clicking down again a few minutes later because it's too loud for my surroundings and situation.  It's a huge volume jump from the lowest setting to completely off, and alot of times the lowest setting is too loud (even with normal buds or headphones).
    The volume limiter setting only limits the upper end, but doesn't change the lower end (just makes the 16 set increments smaller in that reduced range).  I know there is also an option to turn down the volume of individual songs in iTunes options, but this problem applies to all aspects of the iphone beyond just my music library (Music apps, Videos, etc.).
    Why hasn't apple expanded the lower volume limits?  There has to be a way, or is this not possible?  Can anybody think of a way to fix this problem?

    Meg St._Clair wrote:
    Look for headsets with a volume control.
    I did exactly this for awhile.  I used to have Skullcandy Asyms with the inline volume attenuator (wheel).  They've since discontinued them, and my 5 pairs are having wire connectivity issues.  All their current models have iphone like volume mechanisms.  The problem is most headphones with volume controls tap into the phones own volume control (so the set 16 volume increments).  I also looked into using a dongle attenuator, but having the dongle hanging off the phone is just awkward and not easily adjustable.
    I don't know why there can't be some form of internal attenuator option, or some other way of extending the lower range of volume.
    Does anyone else have this problem of the iPhone being too loud in semi-quiet environments?

  • Hi, can someone please tell me why the spell check in pages doesn't work. I went to preferences and enabled this auto spell checker and have set the language to british english. But still it doesn't work while it works perfectly in TextEdit.

    Hi, can someone please tell me why the spell check in pages doesn't work. I went to preferences and enabled this auto spell checker and have set the language to british english. But still it doesn't work while it works perfectly in TextEdit.

    Inspector > Text > More > Language
    Only applies to selected text, like making it a particular font.
    It is not a setting that sticks. If you continue to paste in text from elsewhere particularly the Internet it will have a different or None language set to it. You need to select it and make it B.E.
    Peter

  • Why the execution time increases with a while loop, but not with "Run continuously" ?

    Hi all,
    I have a serious time problem that I don't know how to solve because I don't know exactly where it comes from.
    I command two RF switches via a DAQ card (NI USB-6008). Only one position at the same time can be selected on each switch. Basically, the VI created for this functionnality (by a co-worker) resets all the DAQ outputs, and then activates the desired ones. It has three inputs, two simp0le string controls, and an array of cluster, which contains the list of all the outputs and some informations to know what is connected (specific to my application).
    I use this VI in a complex application, and I get some problems with the execution time, which increased each time I callled the VI, so I made a test VI (TimeTesting.vi) to figure out where the problem came from. In this special VI I record the execution time in a csv file to analyse then with excel.
    After several tests, I found that if I run this test VI with the while loop, the execution time increases at each cycle, but if I remove the while loop and use the "Run continuously" funtionnality, the execution time remains the same. In my top level application I have while loops and events, and so the execution time increases too.
    Could someone explain me why the execution time increases, and how can I avoid that? I attached my test VI and the necessary subVIs, as well as a picture of a graph which shows the execution time with a while loop and with the "run continuously".
    Thanks a lot for your help!
    Solved!
    Go to Solution.
    Attachments:
    TimeTesting.zip ‏70 KB
    Graph.PNG ‏20 KB

    jul7290 wrote:
    Thank you very much for your help! I added the "Clear task" vi and now it works properly.
    If you are still using the RUn Continuously you should stop. That is meant strictly for debugging. In fact, I can't even tell you the last time I ever used it. If you want your code to repeat you should use loops and control the behavior of the code.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • Why doesn't the loop exit?

    I have my program prompting the user for a code in letters.
    System.out.print("Enter Code: ");
    code = TextIO.getlnString();
    code = code.toUpperCase();
    //uppercase so I don't have to code for small letters tooFollowing this I'm using a while loop to check if the code contains numbers or anything other than letters.
    hecknum = (int) code.charAt(p);
    while ((checknum >= 91) || (checknum <= 64)) {
    System.out.println();
    System.out.println("Codes may only contains letters from A to Z.\n");
    System.out.print("Enter Code: ");
    code = TextIO.getlnString();
    code = code.toUpperCase();
    }This only works partially however. If I enter letters the first time through, everything will work fine.
    If I enter numbers or some other symbols, I get the error and am re-prompted for the code. Thing is, if I enter only letters the second time around, I get the error message again, as if I had entered numbers or something.
    I have no clue why... from what I see it should work...
    Can anyone help me figure this out?

    inside the while loop you never change the value of checknum, so if the codition is tru when you enter the loop, it stays true
    looks like you need to change p and recalculate checknum

  • Why doesn't apple have a file of events that ties to the iCal program and the Address book file? By having that relationship it seems that you could call up all of the events tied to a customer while in the address book or likewise call up all of the even

    Why doesn't apple have a file of events that ties to the iCal program and the Address book file? By having that relationship it seems that you could call up all of the events tied to a customer while in the address book or likewise call up all of the events tied to a contact that was in the iCal program as a scheduled meeting. Even in the to do's you could easily look back at the events tied to an individual so as to bring yourself up to speed with what you were doing with the individual in mind.

        I definitely understand your concern and I apologize for all the frustration. Verizon Wireless has a strong customer commitment to delivering the best from our service and staff. I am disappointed to hear the service you received did not reflect this commitment.
    I definitely want to help get to the bottom of this and further assist you. Please reply to my direct message so I can access your account and further assist. I am sure we can get this resolved.
    JohnB_VZW
    Follow us on Twitter @VZWSupport

  • While surfing the internet I get frequent stopages with the notation "Shockwave Flash may be busy - - - - -" Why doesn't it say Adobe Flash and how do I get it fixed?

    While surfing the internet I get frequent stopages with the notation "Shockwave Flash may be busy - - - - -" Why doesn't it say Adobe Flash and how do I get it fixed?

    The  site will NOT let me post in the  "flash player" forum. When I open the  list of forums to post in, I see  flash player listed, but it is grey  in color and you can not click on  it. Under the scroll box that gives  you the choices of forums to post  your question in you see this:
    "Why are some locations grayed out?                                                This means that you can view content in these locations, but may not   have access to post to them. Or, the content type you've chosen is not   available there (i.e. trying to put a blog post in a project where  blogs  are turned off). Also to move content to "Your documents",  "Private  discussions" or "Your Videos" you have to be the author."
    So   tell me HOW the hell am I supposed to post in that forum, when it is   not letting me?  I have had   this problem since back in April, I have tried posting to get help and   all I get is complaints I posted in the wrong place, and it is the SITE   that is not letting me post in the right place.

  • Ending Java War game with while loop

    How would i go about ending a java war game witha while loop. I want the program to run until all of the values of one of the arrays of one of the players split decks has all null values.

    GameObject[] theArrayInQuestion;
    // populate array somehow or other
    void methodWithLoop() {
       while(arrayNotNull(theArrayInQuestion)) {
       // do stuff
    boolean arrayNotNull(Object[] array) {
      int len = array.length;
      for(int i = 0; i < len; i++) {
        if ( array[i] != null ) {
          return true;
      return false
    }

  • While loop doesn't stop until 2 more clicks

    I have to say I am really not familiar with LV at all, but Im learning.
    So, why is that after I clicked stop bottom, I had to click my OK button twice, then my program stopped. Why it can't stop immediately?
    Besides, if I want to some the dice result by array, which wire am I missing?
    Thank you!
    Solved!
    Go to Solution.
    Attachments:
    dice.vi ‏15 KB

    Hi RawtoLV,
    You have a while loop within a while loop. When you run the other while loop stops when you pressed the stop button, the inner while loop still runs. Since your OK button is using Latch when released, what i noticed is that when you pressed that OK button, it quickly switched to from true to false which didn't stop that while loop operation (could be due to the wait). May I ask what are you actually doing with the sequence structure?
    I would suggest using event structure instead (http://zone.ni.com/reference/en-XX/help/371361K-01/glang/event_structure/):
    here some more info on event structure:
    http://www.ni.com/white-paper/3331/en/
    http://www.youtube.com/watch?v=8eO64fo3Pho
    Warmest regards,
    Lennard.C
    Learning new things everyday...

  • Why doesn't apple tv show song info while using pandora with AirPlay?

    Why doesn't apple tv show song info while using pandora with AirPlay?

    Welcome to the Apple Community.
    I'm not really familiar with Pandora but I assume it's an audio app and the app places text on screen to inform you of the current track playing.
    As an audio app, it seems to make sense it will stream audio over AirPlay, which doesn't include text of course. For that matter the text is also unlikely to be a video stream either, just to cover the possibility you ask why can't they stream it over AirPlay as video.

  • Allow state machine while loop to end only in 1 of the states?

    What is the best way to ensure that the while loop that surronds state machine case structure only ends in a certain one of the states?

    I have solved the problem of having the VI not stopping (apparently it was due to an event structure). However, now I have another slight problem. I need the state machine to terminate on either of two conditions:
    1) If a stop button is pressed
    OR
    2) if the end of the sequence is reached.
    As I have implemented it so far the VI terminates because of the second condition and does not allow me to terminate it by pressing a 'Stop' boolean button. I know that this might be a bit fundamental and simple but I'm new with state machines on labview.
    Thanks.
    Attachments:
    State machine.vi ‏21 KB

  • Why writes LabVIEW only every 2 seconds the measured Value to a Excel (In a while loop with 100 ms tact)?

    Hi everybody,
    I use the myDAQ to measure speed, ampere, and voltage of a battery driven motor. (For Current measurement, i use a Sensor which outputs a 0-10 V signal). I placed all DAQ-Assitants in a while loop with a [Wait until next ms multiple] clock and set a value of 100 ms. I thougt, Labview will now write into my text file 10 times a second all values. In fact, as you can see in the attached text file, Labview only writes in a unsteady interval of 1-2 seconds a value, which is too less.
    The question: Did I do anything wrong, how can you create VI that writes you lets say 10 values a second into text file? Or is simply the DigitalMultimeter input of the myDAQ not able to sample a rate of 10 Hz? I couldn´t find any information in the specification handbook about the sample rate of the DMM?
    If anyone can help me would be great! Thanx a lot, Markus
    Attachments:
    Measure Speed+Current+Voltage into Excel.vi ‏175 KB
    Test7.txt ‏1 KB

    File I/O is not very efficient. I recommend that you do you file logging in a parallel task. Have one task do your data acquision. This task would then pass the data to be logged to the logging task via a queue. That way your file operations do not impact your data acquision. Also, express VIs are not very efficient. You would be better off accessing that directly using the DAQ VIs. The express VIs contain lots of steps that do not need to be done every time you call it such as initializing the device.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • End a while loop

    For this example:
    int x = 1, y = 2;
    while (x == 1)
    if (y = 2)
    y -= 1;
    if (y = 1)
    y -= 1;
    }Is there a line I can put in the first if statement block to make the loop and and repeat? I'm having a problem with if statements that after one is true, it makes one following it also true. I only want one to be executed, so if I could make the while loop repeat after an if statement is true, I could fix that problem

    I'm having a problem with if statements that after one is true, it makes one following it also true. I only want one to be executedOr perhaps "else if"
    while(foo) {
      if(cond1) {
        cond2 = true;
      } else if(cond2) {
        cond1 = true;
    }

Maybe you are looking for