Results 1 to 5 of 5
  1. #1
    javapro2015 is offline Member
    Join Date
    Mar 2013
    Posts
    4
    Rep Power
    0

    Default Infinite loop with messgae null...why?

    Java Code:
    import java.io.*;
    
    public class file13
    
    {   public static void main(String args[])
        {
           try
             {
              RandomAccessFile f = new RandomAccessFile("d:/abc.txt","rw");
              f.seek(f.length());
              long a = f.length();
              System.out.println("\n length of file:" + f.length() + a);
              DataInputStream d = new DataInputStream(System.in);
              String name = new String();
              int age;
              int i = 0;
              float height;
              String res;
              res = "y";
    //          System.out.println(ans);
          //    while (i==0)
              do  {
                System.out.println("\n Enter Name:");
                name = d.readLine();
                System.out.println("\n Enter Age:");
                age =Integer.parseInt(d.readLine());
                System.out.println("\n Enter Height:");
                height = Float.valueOf(d.readLine());
                f.writeBytes("\n" + name + " " + age + " " + height);
    
              [B]  System.out.println("\n Do you want to continue? (y):" );
                res =d.readLine();
     [/B]         [B]//  if (!res.equals("y")) [/B]
    [B]             // return;
              //   break label1;
              if(res.equals("y"))
               {System.out.println("true");
                i++;
                continue;
               }
              else
              { System.out.println(res);
                break;
              // f.close();
               }
    
                }while(i>0);
    [/B]        if (i>0)
              f.close();
             System.out.println("here");
    This program is going in an infinite loop displaying the msg "null" "here" alternately whenever an user types n or any character apart from y .Thats the reason I have changed the code many times.

    Please suggest ...why is it displaying null and going in infinite loop..
    Last edited by javapro2015; 03-02-2013 at 09:09 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,271
    Rep Power
    25

    Default Re: Infinite loop with messgae null...why?

    Please edit your post and wrap the code i code tags. See:
    BB Code List - Java Programming Forum - Learn Java Programming
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    javapro2015 is offline Member
    Join Date
    Mar 2013
    Posts
    4
    Rep Power
    0

    Default Re: Infinite loop with messgae null...why?

    Dont seem to understand ur response???

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,271
    Rep Power
    25

    Default Re: Infinite loop with messgae null...why?

    Please edit your post and wrap your code with
    [code]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Jamil37037 is offline Member
    Join Date
    Feb 2013
    Location
    Islamabad, Pakistan
    Posts
    25
    Rep Power
    0

    Default Re: Infinite loop with messgae null...why?

    Unable to understand your code. Please post the original one you are trying to use.

Similar Threads

  1. Infinite loop
    By jyde001 in forum Java Applets
    Replies: 4
    Last Post: 08-09-2012, 01:13 AM
  2. Infinite loop
    By F.S. in forum New To Java
    Replies: 3
    Last Post: 03-09-2012, 12:52 PM
  3. Infinite loop
    By jDennis79 in forum New To Java
    Replies: 7
    Last Post: 08-13-2010, 11:45 PM
  4. Infinite Loop
    By bosoxfan in forum New To Java
    Replies: 3
    Last Post: 02-22-2010, 01:34 AM
  5. Infinite Loop
    By rclausing in forum New To Java
    Replies: 2
    Last Post: 01-23-2010, 10:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •