Small Looping Problem

Alright here's the prob. I have an assignment to create a method using if/else statements. Extra credit is given if a loop is added. The if/else works fine and the loop pretty much does too. The only problem is when the sentinel value is entered, I get a String that I don't want to appear, "Temperature is out of range."
Heres the code:
import java.util.Scanner;
public class LabAssign8
     public static void main( String [ ] args )
          final int SENTINEL = 999;
          int temp;
          System.out.print( "Enter a temperature > " );
          Scanner scan = new Scanner( System.in );
          temp = scan.nextInt( );
          LabAssign8.findSeason( temp );
          while ( temp != SENTINEL )
               System.out.print( "Enter a temperature > " );
               temp = scan.nextInt( );
               LabAssign8.findSeason( temp );
          System.out.println( "Sentinel value detected, ending program." );
     public static void findSeason( int temp )
          if ( temp > 115 || temp < -15 )
               System.out.println( "The temperature is out of range" );
          else if ( temp >= 80 )
               System.out.println( "It is probably summer." );
          else if ( temp >= 60 )
               System.out.println( "It is probably spring." );
          else if ( temp >= 40 )
               System.out.println( "It is probably fall." );
          else
               System.out.println( "It is probably winter." );
So when the user enters 999, I want the only output to be: "Sentinel value detected, ending program."
Any help is appreciated, thanks.

I don't know why it posted that way, that isn't how it looks in my IDE. It doesn't look like anything is missing, I'll post the code and the compiler errors.
import java.util.Scanner;
public class LabAssign8
     public static void main( String [ ] args )
          final int SENTINEL = 999;
          int temp;
          Scanner scan = new Scanner( System.in );
          while ( true )
               System.out.print( "Enter a temperature > " );
               temp = scan.nextInt( );
          if ( temp == SENTINEL )
               break;
               LabAssign8.findSeason( temp );
     System.out.println( "Sentinel value detected, ending program." );
     public static void findSeason( int temp )
          if ( temp > 115 || temp < -15 )
               System.out.println( "The temperature is out of range" );
          else if ( temp >= 80 )
               System.out.println( "It is probably summer." );
          else if ( temp >= 60 )
               System.out.println( "It is probably spring." );
          else if ( temp >= 40 )
               System.out.println( "It is probably fall." );
          else
               System.out.println( "It is probably winter." );
}Compiler errors:
Line 31: Illegal start of expression
Line 58: ';' expected
Line 58: '}' expected

Similar Messages

  • Best way to capture data every 5 ms (milli-seconds) in the .vi diagram when using "Time between Points, and Small Loop Delay tools" ?

    - Using LabView version 6.1, is there anyway to change the "Time Between Points" indicator of (HH.MM.SS) to only (mm.ss), or to perhaps only (.ss) ?
    - Need to set the data sampling rate to capture every 5 milliseconds, but the defaults is always to 20 or greater; even when the "Small Loop Delay" variable is adjusted down. 
    Thank you in advance.

    I have no idea what "Time between Points, and Small Loop Delay tools" is. If this is some code you downloaded, you should provide a linke to it. And, if you want to acquire analog data every 5 milliseconds from a DAQ board, that is possible with just about every DAQ board and is not related to the version of LabVIEW. You simply have to set the sample rate of the DAQ board to 200 samples/sec. If it's digital data, then there will be a problem getting consistent 5 msec data.

  • Not the usual 'login loop' problem, help.

    The login loop problem I'm facing is not the usual login loop problem when starting up mac; it's when I'm trying to log into websites or applications (most of them, eg. facebook, instagram).
    I have tried:
    using other browsers: Safari, Firefox, Maxthon, Chrome
    clearing all cookies / caches / keychains / passwords
    repairing disk
    deleting launchservices cache
    using other userid to login
    All to no avail.
    How do I solve this without having to reformat/install mac?
    Thank you.

    Hi, are you using Parental contrils or a managed account, or an admin account?
    Using any Anit-Vrus software?

  • Trying SSH CLI ,  reading command line method is infinte loop problem!

    I am trying excute command and reading result. but reading result part has problem.
    below source is a part of my method.
    try{
                   SessionChannelClient sessionChannel = ssh.openSessionChannel();
                   sessionChannel.startShell();
                   OutputStream out = sessionChannel.getOutputStream();
                   String cmd = s + "\n";
                   out.write(cmd.getBytes());
                   out.flush();
                   InputStream in = sessionChannel.getInputStream();
                   BufferedReader br = new BufferedReader(new InputStreamReader(in));
                   byte buffer[] = new byte[255];
                   String read= "";
                   while (true) {
                        String line = br.readLine();
                        if (line == null)
                             break;
                        str += line;
                        str += "\n";
                   System.out.print(str); //print result
                   sessionChannel.close();
                   in.close();
                   out.close();
              }catch(IOException ee){
                   System.out.println(ee);
              }finally{
                   System.out.println("=============end cmd=============");
    while loop has problem. While statement has infinite loop problem.
    why has this problem?
    anybody, help me please. Thanks for reading .
    Edited by: BreathAir on Aug 5, 2008 12:16 AM

    That loop will loop until readLine() returns null, which will only happen when the other end closes its end of the connection, and it will block while no data is available.

  • Small SQL problem

    Hello,
    I have a small SQL problem...
    I am designing an online bank using servlets for a university project and it allows customers to view their statements. They select which of their account numbers they want to view the statement for and the start and end date of the statement.
    The problem lies with the dates. Here is the SQL:
    SELECT date, details, amount, balance
    FROM HISTORY
    WHERE bankaccnumber=13494925 And date>=1/1/01 And date<=31/1/01;
    All of the books I have looked at show dates in '1/1/01' format but whenever I try it this way I get a 'Data type mismatch in criteria expression' error (the 'date' field in the Database IS a Date type).
    Although, whenever I run the query in Access and prompt the user to enter the start and end date, it works fine.
    I have spoken to a few people and no-one seems to know why it is not working.
    Any ideas???
    Thanks

    If your database is MS Access and you don't expect to switch to something else, then write this:
    SELECT date, details, amount, balance
    FROM HISTORY
    WHERE bankaccnumber=13494925 And [date]>=#1/1/01# And [date]<=#1/31/01#
    Note that you MUST format your dates as MM/DD/YY and not as DD/MM/YY, that's an Access rule, and that you will probably have to "quote" your column name "date", which I think is a reserved word in SQL and hence a bad choice for column name.
    Personally I always use PreparedStatements. That way my SQL would look like this:
    SELECT date, details, amount, balance
    FROM HISTORY
    WHERE bankaccnumber=13494925 And date>=? And date<=?
    and I would use the setDate() method to fill in the parameters. Since this method uses a Date as a parameter, I don't need to fight with date formats, the JDBC driver handles that for me.

  • Can Lincat find big endian and small endian problem?

    Hi, I want to migrate a project from linux to solaris. And I read that lincat can save a lot of time in migration. But when I tried with lincat. I found that what is found is mainly the difference between linux API and solaris API. I use the following
    codes:
    #include <stdio.h>
    #include <stdlib.h>
    int main(int argc, char *argv[])
    int flagVal = 0x01020304;
    char cptr = (char )&flagVal;
    printf("Val is %d\n", *cptr);
    my lincat does not find the big endian and small endian problem. I also wonder whether lincat can find the misaligned problem and "32 bits and 64 bits" problem. Could you please tell me? I didn't find the answer from lincat manual.
    Edited by: baiwd on May 6, 2008 6:03 PM

    Hi Ankit,
    You may use "Cross Platform Transportable Tablespaces" method if the endian format is different between source and target platforms. Please have a look at Oracle's "Platform Migration Using Transportable Tablespaces" document for more information: http://www.oracle.com/au/products/database/maa-wp-11g-platformmigrationtts-129269.pdf
    Please note that "Transportable Database" is a different feature and can only be used to migrate a new database platform that has the same endian format.
    BR,
    Alper Somuncu

  • Sony D-50 "boot-up loop" problem

    I have a Sony D-50 portable recorder barely three months old that did something totally strange. Has anyone else had this problem?
    During a shoot yesterday, I noticed that the Sony D50 I bought back in August would not turn OFF.
    When I moved the power switch to the OFF position, the machine went into a "boot up loop," that is:
    I'd turn it OFF after recording.
    Screen goes black.
    I get the "See you!" message.
    Screen lights up again.
    The word "SONY" appears as though it's gonna boot up,
    Then the whole process starts over again
    Screen goes black.
    I get the "See you!" message.
    Screen lights up.
    The word "SONY" appears as though it's gonna boot up....
    So, same thing late last night.
    I get up this morning and turn it ON; it works fine until I turn it off, then it goes back into the "boot loop" thing again.
    I tried everything I could think of, even searching for a "RESET" on the machine and in the Menu. I finally had to take the batteries out of it to shut it down.
    Then, I did something that apparently---so far---fixed it.
    This is so strange---right out of the Twilight Zone:
    I put the batteries back in it, then it starts the loop again.
    Since it won't turn OFF, I take the batteries out of it in the OFF position. I wait five minutes and put the batteries back in it with it in the OFF position.
    Same problem---the "boot up loop" thing.
    I take the batteries back out of it again in the OFF position and wait fifteen minutes. I put the batteries back in it while it's still in the OFF position. Guess what?
    Problem solved: It's doesn't start the "boot up loop" thing.
    So, I turn it back ON. Machine boots up fine and is ready to record.
    OK, I turn it OFF.
    Back to the exact same problem---It shuts down and goes into the "boot up loop" again.
    I go back through the same process of removing and installing the batteries with the machine in the OFF position.
    Nothing changes.
    Then, I have an idea.
    With the machine in the OFF position and going through the "boot up loop" thing, I remove the batteries.
    I then move the power switch to the ON position before I put the batteries back in it---had not tried that before: reinstalling the batteries with it in the ON position. I install the batteries with the machine in the ON position.
    Machine boots up fine and is ready for recording.
    Now, I turn it OFF.
    The machine shuts down fine with no "boot up loop" problem.
    Putting the batteries back in the machine with it in the ON position instead of the OFF position apparently solved the problem.
    So, I turn it back ON and then OFF several times.
    Same thing: No "boot up loop" problem.
    Do-do-Do-do....
    The machine now works fine.
    Anyone ever had this happen to a Sony D-50?
    I'm wondering if I should send it to back to Sony before it does this again. For God's sake, it's only three months old!
    I bought it after rave reviews in the "recorder" community, and I haven't found anyone else who has had this problem with one..

    Sorry to see that you were having this issue with your PCM-D50 Linear PCM Recorder - if you continue having the issue the unit may need service - give Sony Business and Professional team a call and they will be happy to assist:
    http://pro.sony.com/bbsc/ssr/services.s ... port.shtml

  • Possible solution to "Looping" problem

    Hello all, I've read several threads here dealing with a "looping" problem, I'm not sure what the ins-and-outs of this issue is but it seems to affect many different config and different manufacturers are blaming each other... check out the link below (mind the wrapping) for what might be a real solution at the Via forums. I happened upon this because I could not get a stable system out of my MSI via-km266 mobo with dual display.
    http://forums.viaarena.com/messageview.cfm?catid=25&threadid=9263&highlight_key=y&keyword1=dual%20display
    Alpay Eno

    What is the problem? Let the filters return a List instead of an array. Am I missing something?
    Kaj

  • Rows of Data cannot be inserted (Loop Problem) (urgent)

    Hi Guys
    create table JobWorker
    (JobID               Integer,
    JobName          char(20),     
    Name               char(20),      
    Department          char(20),
    Responsibilities char(30),
    JobRating char(20),
    Primary Key (JobID));
    Above is my table that requires rows of data.
    Create sequence demoseq increment by 1 start with 1;
    DECLARE
    v_rows integer := 1000; -- THIS IS THE KEY VALUE = NUMBER OF ROWS IN TABLE
    v_JobName char(20);
    v_temp integer := 1;
    BEGIN
    FOR v_counter IN 1 .. v_rows LOOP
    IF (v_temp > 10) THEN
    v_temp := 1;
    END IF;
    IF (v_temp = 1) THEN
    v_JobName := 'Pharmacist';
    insert into JobWorker values (demoseq.nextval, v_JobName, 'Richard Smith','Medical', 'Import and Export', 7);
    ELSIF (v_temp = 2) THEN
    v_JobName := 'Security Officer';
    insert into JobWorker values (demoseq.nextval, v_JobName, 'Matt Stevens', 'Security', 'Check Club Tickets', 6);
    ELSIF(v_temp = 3) THEN
    v_JobName := 'Systems Analyst';
    insert into JobWorker values (demoseq.nextval, v_JobName, 'Navdeep Kamboz', 'Finance', 'Analyse Systems', 10);
    ELSIF(v_temp = 4) THEN
    v_JobName := 'Mathematician';
    insert into JobWorker values (demoseq.nextval, v_JobName, 'Paul Potts', 'Algebra and Data Handling', 'Teach Algebra', 4);
    ELSIF(v_temp = 5) THEN
    v_JobName := 'DB Administrator';
    insert into JobWorker values (demoseq.nextval, v_JobName, 'Christine Bleakley', 'Oracle, SQL, DB2', 'Granting User Privileges', 9);
    ELSIF(v_temp = 6) THEN
    v_JobName := 'Dentist';
    insert into JobWorker values (demoseq.nextval, v_JobName, 'Edward Walker', 'Manager', 'General Checkups', 8);
    ELSIF(v_temp = 7) THEN
    v_JobName := 'Electrician';
    insert into JobWorker values (demoseq.nextval, v_JobName, 'Dave Panesar', 'Engineering', 'Examine Specifications', 3);
    ELSIF(v_temp = 8) THEN
    v_JobName := 'Cricketer';
    insert into JobWorker values (demoseq.nextval, v_JobName, 'Sachin Tendulkar', 'Batsman', 'Scoring Hundreds', 9);
    ELSIF(v_temp = 9) THEN
    v_JobName := 'Personal Trainer';
    insert into JobWorker values (demoseq.nextval, v_JobName, 'Brock Lesnar', 'Weights Dept', 'Train People on Weights', 5);
    ELSIF(v_temp = 10) THEN
    v_JobName := 'Area Manager';
    insert into JobWorker values (demoseq.nextval, v_JobName, 'Joe Hoffland', 'Midlands', 'Visit Stores and Examine', 2);
    END IF;
    END LOOP;
    END;
    It does work...but the following problems I get are...
    As you can see I have populated the tables as a Loop..
    But if I was to generate a statement : Select * from JobWorker WHERE Name = 'Joe Hoffland';
    It provides me with the result as 'No Rows Selected'.
    The first Insert consists of someone called Richard Smith. Every row of data is only populated with his name and his row of data.
    I cannot get the other 9 insert rows to work....
    Is there something wrong with the above code? I require your help guys! Thank You!

    Incrementing v_temp would help :). Also column department length is too small. You need to increase it to 25. And sing CHAR isn't a good idea. Use VARCHAR2 instead:
    SQL> DECLARE
      2  v_rows integer := 1000; -- THIS IS THE KEY VALUE = NUMBER OF ROWS IN TABLE
      3  v_JobName char(20);
      4  v_temp integer := 1;
      5 
      6  BEGIN
      7  FOR v_counter IN 1 .. v_rows LOOP
      8 
      9  IF (v_temp > 10) THEN
    10  v_temp := 1;
    11  END IF;
    12 
    13  IF (v_temp = 1) THEN
    14  v_JobName := 'Pharmacist';
    15  insert into JobWorker values (demoseq.nextval, v_JobName, 'Richard Smith','Medical', 'Import and Export', 7);
    16  ELSIF (v_temp = 2) THEN
    17  v_JobName := 'Security Officer';
    18  insert into JobWorker values (demoseq.nextval, v_JobName, 'Matt Stevens', 'Security', 'Check Club Tickets', 6);
    19  ELSIF(v_temp = 3) THEN
    20  v_JobName := 'Systems Analyst';
    21  insert into JobWorker values (demoseq.nextval, v_JobName, 'Navdeep Kamboz', 'Finance', 'Analyse Systems', 10);
    22  ELSIF(v_temp = 4) THEN
    23  v_JobName := 'Mathematician';
    24  insert into JobWorker values (demoseq.nextval, v_JobName, 'Paul Potts', 'Algebra and Data Handling', 'Teach Algebra', 4);
    25  ELSIF(v_temp = 5) THEN
    26  v_JobName := 'DB Administrator';
    27  insert into JobWorker values (demoseq.nextval, v_JobName, 'Christine Bleakley', 'Oracle, SQL, DB2', 'Granting User Privileges',
    9);
    28  ELSIF(v_temp = 6) THEN
    29  v_JobName := 'Dentist';
    30  insert into JobWorker values (demoseq.nextval, v_JobName, 'Edward Walker', 'Manager', 'General Checkups', 8);
    31  ELSIF(v_temp = 7) THEN
    32  v_JobName := 'Electrician';
    33  insert into JobWorker values (demoseq.nextval, v_JobName, 'Dave Panesar', 'Engineering', 'Examine Specifications', 3);
    34  ELSIF(v_temp = 8) THEN
    35  v_JobName := 'Cricketer';
    36  insert into JobWorker values (demoseq.nextval, v_JobName, 'Sachin Tendulkar', 'Batsman', 'Scoring Hundreds', 9);
    37  ELSIF(v_temp = 9) THEN
    38  v_JobName := 'Personal Trainer';
    39  insert into JobWorker values (demoseq.nextval, v_JobName, 'Brock Lesnar', 'Weights Dept', 'Train People on Weights', 5);
    40  ELSIF(v_temp = 10) THEN
    41  v_JobName := 'Area Manager';
    42  insert into JobWorker values (demoseq.nextval, v_JobName, 'Joe Hoffland', 'Midlands', 'Visit Stores and Examine', 2);
    43 
    44  END IF;
    45  v_temp := v_temp + 1;
    46  END LOOP;
    47  END;
    48  /
    PL/SQL procedure successfully completed.
    SQL> Select * from JobWorker WHERE Name = 'Joe Hoffland';
         JOBID JOBNAME              NAME                 DEPARTMENT                RESPONSIBILITIES               JOBRATING
            10 Area Manager         Joe Hoffland         Midlands                  Visit Stores and Examine       2
            20 Area Manager         Joe Hoffland         Midlands                  Visit Stores and Examine       2
            30 Area Manager         Joe Hoffland         Midlands                  Visit Stores and Examine       2
            40 Area Manager         Joe Hoffland         Midlands                  Visit Stores and Examine       2
            50 Area Manager         Joe Hoffland         Midlands                  Visit Stores and Examine       2
           120 Area Manager         Joe Hoffland         Midlands                  Visit Stores and Examine       2
           130 Area Manager         Joe Hoffland         Midlands                  Visit Stores and Examine       2
           140 Area Manager         Joe Hoffland         Midlands                  Visit Stores and Examine       2
         JOBID JOBNAME              NAME                 DEPARTMENT                RESPONSIBILITIES               JOBRATING
           970 Area Manager         Joe Hoffland         Midlands                  Visit Stores and Examine       2
           980 Area Manager         Joe Hoffland         Midlands                  Visit Stores and Examine       2
           990 Area Manager         Joe Hoffland         Midlands                  Visit Stores and Examine       2
          1000 Area Manager         Joe Hoffland         Midlands                  Visit Stores and Examine       2
    100 rows selected.
    SQL> SY.

  • Delay loop problem

    I have a small problem with adding a delay to a for loop.I didn attach the whole coding but just a simple example just so u guys can understand what i am asking here..as u see ive introduced a 2000 msec delay in for loop..but as soon as i click run in this case the tank value changes to 3 but i want the calue to show 3 only after 2sec(2000msec).. how do i achieve this?
    Attachments:
    test5.vi ‏8 KB

    You could also delay the start of the loop by 2000ms. There are many possibilities, here are two more. The rest of the code will dictate the best way to do this.
    The secret is in dataflow and data dependency. Use execution highlighting to get a better understanding of it all.
    Message Edited by altenbach on 04-27-2008 11:00 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    updatedelay.png ‏14 KB

  • Game center registration loop problem

    I have tried to reigister for the game center with my Apple ID and the message that the Apple ID has not been used in Game center... I tap continue. I enter my location, then my date of Birth.
    After this I get the same message again. "This Aplle ID has not yet been used in Game center" and i'm asked to enter my location again and then DOB and then I go back to the same message. I can't get past this loop.
    (I have tried turing up phone off and on again, and it still does not work)
    can any one help me ?

    I had exactly the same problem on my sons ipod 4th gen.
    I tried logging on using my phone and it worked fine.

  • Infinite loop problem

    Hi there,
    This is the second time I have posted this problem, as the last solution I was offered did not seem to work. Here is the problem:
    I have written a method to search through a text file for a word and replace it with another word. That word can either be on its own in the document or as part of another word. So, if the search word was "foot" and the replace word was "dog", the word "football" in the document would become "dogball".
    This method works fine, except for when the replace word is the same as the search word. Basically, if someone searched for "dog" and wanted to replace it with "dog dog" or even just "dog", the program goes into an infinite loop. I understand why it is doing this, but I don't know how to prevent it from happening.
    Now, to make it worse I have to stick to this array style structure and method of solving the problem. I know there is a way to do this by building temporary strings and then concatenating them at the end and returning them to their previous position in the array. The reason I know this is because a friend of mine has managed it. She also happens to be a girl.
    So, I am asking you all to assist in defending men's intelligence by helping me see where I am going wrong in this method. Please.
    Here is the method:
    // Search the document for a string and replace it with another string        
         public String [] SearchReplace() {
              // Declare variables to be used in the method
              String SecondSubstring;
              String FirstSubstring;
              int ReplaceNumber = 0;
              // Loop through the lines of text stored as strings contained in the array
              for (int i = 0; i < NumberOfLines; i++) {
                        // As long as the string contains an instance of the search string, run the method                    
                        while (StrArray.indexOf(SearchW) >= 0) {
                             // Make a string of all the characters after the search word
                             SecondSubstring = StrArray[i].substring(StrArray[i].indexOf(SearchW) + SearchW.length());
                             // Make a string of all the characters before the search word
                             FirstSubstring = StrArray[i].substring(0, StrArray[i].indexOf(SearchW));
                             // Concatenate FirstSubstring with the replace word to make a new string
                             String FirstHalf = FirstSubstring.concat(ReplaceW);
                             // Concatenate the new string with SecondSubstring to make the whole replaced string
                             String FullString = FirstHalf.concat(SecondSubstring);
                             // Put this altered string back to its original place in the array
                             StrArray[i] = FullString;
                             // Increment ReplaceNumber to count the replacements made
                             ReplaceNumber++;
              // Print the numbers of replacements made
              System.out.println("\nA total of " + ReplaceNumber + " changes made.\n");
              // Display the searched and replaced contents of the file
              return StrArray;
    Any suggestions, pointers or solutions would be much appreciated.
    Thanks very much.

    Doing it the "old fashioned" way:
    You need to keep track of a "from index" so you don't search through parts of the string you've already replaced:
           public static void main(String args[]) {          
              try {     
                   String[] lines = new String[] {
                        "the dog went up the dog hill",
                        "all dogs go to dog heaven",
                        "the dogball takes place on 3rd april"
                   lines = replace(lines, "dog", "dog dog");
                   for (int i = 0; i < lines.length; i++) {
                        System.out.println(lines);
              } catch (Exception e) {
                   e.printStackTrace();
         private static String[] replace(String[] lines, String searchWord, String replaceWord) {
              if (searchWord.equals(replaceWord)) return lines; // nothing to do          
              for (int i = 0; i < lines.length; i++) {
                   int fromIndex = 0; // from index to do indexOf
                   String line = lines[i];
                   while (line.indexOf(searchWord, fromIndex) != -1) {
                        final int index = line.indexOf(searchWord, fromIndex);
                        line = line.substring(0, index) + replaceWord + line.substring(index + searchWord.length());
                        fromIndex = (line.substring(0, index) + replaceWord).length();
                   lines[i] = line; // replace
              return lines;

  • Do while loop problem

    I have a problem with do while loop. I am displaying a dialogue box where a person should enter the type of quiz he had performed. The problem is that the user should enter only the following 3 words, either "Earthquakes" or "Place" or "Animals". If the user enters any other word, he/she should be displayed wwith another message saying "Invalid". This should keep repeatinf (i.e. displaying invalid) until the user enters either of those 3 words. When a user enters one of those words it will stop diplaying "Invalid". I tried doing this, but altough it displays "Invalid" when a user enters an invalid word, it will display invalid also when a user neters the correct word. I think i have something wrong with the loop.
    This is the code:
         String player = JOptionPane.showInputDialog(null, "Enter name");
                 String type = JOptionPane.showInputDialog(null, "Enter your quiz type");
                do
                    type = JOptionPane.showInputDialog(null, "Invalid entry. Try again." );
                 while (type != "Earthquakes"  || type != "Place" || type != "Animals" );

    Yeah thats a good idea, but i'm still a beginner and i'm still new to some things. I got a problem, because altough the while loop is working correctly, however the first time i enter a word even if its correct its still displays invalid. I think that thats a property of the while loop. So can someone pls tell me how can i change this loop and use another loop that wouldn't do this. Can i use perhaps a for loop instead here? Thanks a lot.
    String player = JOptionPane.showInputDialog(null, "Enter name");
              String type = JOptionPane.showInputDialog(null, "Enter your quiz type");
                  do {
                      type = JOptionPane.showInputDialog(null, "Invalid entry. Try again." );
                   } while(!type.equals("Earthquakes") && !type.equals("Places") && !type.equals("Animals"));
                Edited by: datax on Feb 21, 2008 10:46 AM

  • While loop problem

    I have a problem with a while loop in this code and it is really holding me up doing my degree. I can see nothing wrong with it but perhaps someone here can help. I would be really greatful if someone could. I have commented the line where the while loop starts about a third of the way down the code.
    Thanks
    Michael
    if (ae.getSource()==client_open)
    int row=0;
    check=true;
    row=client_listing.getSelectedRow();
    try
    System.out.println("information[row][1] is "+information[row][1]);
    if(information[row][1]!=null) //if the index is not null. Comment out this if statement to troubleshoot
    try
    InetAddress inet=InetAddress.getByName(information[row][1]);
    //Create a client socket on the listeners machone on port 7070
    client_socket=new Socket(inet,7070);
    System.out.println("Client port open on 7070 ");
    //Get the output as well as the input streams on that socket
    BufferedOutputStream out=new BufferedOutputStream(client_socket.getOutputStream());
    BufferedInputStream br_socket=new BufferedInputStream(client_socket.getInputStream());
    XMLWriter writer=new XMLWriter();
    writer.requestFString("SHOWFILES"," ");
    String file_data=writer.returnRequest();
    byte file_bytes[]=file_data.getBytes();
    int file_size=file_bytes.length;
    byte b[]=new byte[1024];
    // The methos takes a byte array and it's length as parameters and return
    // a byte array of length 1024 bytes....
    add_on upload=new add_on();
    System.out.println("Class of add_on created sucessfully");
    b=upload.appropriatelength(file_bytes,file_size);
    out.write(b,0,1024);
    /*An output stream is also initialised. This is used to store all the response
    from the listener */
    BufferedOutputStream out_file=new BufferedOutputStream(new FileOutputStream("response.xml"));
    int y=0;
    byte f[]=new byte[32];
    System.out.println("Entering while loop");
    //This while loop is not working. Any ideas. It just hangs here
    while((y=br_socket.read(f,0,32))>0) //the socket input stream is read
    out_file.write(f,0,y); //written on to the file output stream, y bytes from f start @ ofset 0
    out.close();
    br_socket.close();
    out_file.close();
    System.out.println("Exited while loop and closed streams");
    catch(Exception e)
    client_socket=null;
    check=false;
    System.out.println("Didnt enter try");
    try
    client_socket.close();
    catch(Exception e)
    System.out.println("Error occuered "+e.getMessage());
    row=0;
    if(check) //If the exception occurs then do not come here
    Vector parameters=new Vector();
    // A class SParser is also used here this class has a function/method of
    // the name perform which calls the xml parser to parse the xml file
    // generated by the response from the client soket...
    // the function perform returns a Vector which has the files/directories,
    // along with their flag information and size in case of files....
    SParser sp=new SParser();
    System.out.println("SParser object created sucessfully");
    parameters=sp.perform("response.xml");
    System.out.println("Parsing finished ");
    // The vector value returned by the xml parseris then passed as one of
    // the parameters to a class named file_gui this class is responsible for
    // displaying GUI consisting of a table and some buttons along with the
    // root information and flag..
    // Initially since the class is called for the first time the parameter
    // for the root is given the name "ROOT" and the Flag is set to "0"..
    file_gui showfiles=new file_gui(parameters,information[row][1],"Root","0");
    showfiles.show();
    check=false;
    } //end if
    } // end if
    } //end try
    catch(Exception e)
    row=0;
    } //end of ae.getSource()

    Why do you think it hangs at the while loop, eh? You need to put in additional printlns to justify your assertion. It takes alot less time to diagnose if you put in specific try/catch blocks with their own printlns - even if it is not as much fun. When you get into these kinds of troubles, there is no shame in putting in prints at each statement or logical point to track down the actual fault.
    ~Bill

  • External monitor causes earth loop problems

    When i connect an external monitor to my macbook pro it creates horrible interference, soudns like an earth loop somewhere but i can't stop it.
    Is very irritating!
    Any suggestions would be much appreciated.
    cheers,
    josh

    still has horrible interference. Think its not an earth problem now as the interence is more than a simple hum problem, it changes when i click mosue or open applications and can hear digital nastiness to it.
    I spoke to a lecturer at uni who has the same problem he seems to thinks its a design fault with the core audio processors position i nthe mac. Its very near next to the circuits for the external monitor and it causes the intereference or soemthing like that when an external monitor is connected. Though mac are known to be good for msuci production for stablilty and software support the core audio is far too noisey even without external monitor plugged in so i feel the only way to resovle this is with an external soudncard. When used with my RME fireface the interference disappears but this card is for my PC as i don't wanna be taking out adn about with me for obvious reasons! Maybe a nice edirol FA-66 will be in my stocking at christmas...
    cheers for the reply.

Maybe you are looking for

  • How to set up a local testing server with local-only access

    Hi folks, I've reached the point where I need to do some simple server-side scripting in my Dreamweaver work. I work remotely pretty often, so I want to be able to preview my work without having to go back and forth to the production server. It seems

  • This operation has been cancelled due to restrictions in effect on this computer

    We are running Windows 2003 TS for client access their report. We create a group policy to "Hide these specified drives in My Computer" and "Prevent access to drives from My Computer". The problem is when a TS user tries to save the PDF report, he re

  • Parsing xml with namespaces

    Hi I have to parse a xml file with 2 namespaces. The file looks like as follows <AA xmlns="http://XX.com/provider/C/D/E/F/2010/"> <BB xmlns=""> <Id>262</Id> <Time>2011-03-10T13:55:00.000-06:00</Time> <Indicator>true</Indicator> </BB> </AA> i tried fo

  • IE can't show slide show on one Win200 sys, but works fine on another

    As the happy owner of a new MacBook Pro, I spun up a simple website through iWeb. I run my own Apache server on a Redhat system so I ported the test site to that and set up the permissions as necessary. With Safari I can visit the site and when I cli

  • ONE PR ONE PO

    Hi Friends,                           I have created PR. But in our system, it is allowing us to create multiple PO's with the same PR Number. Can anybody convey how to avoid it? Regards,