Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: why the while loop is not terminating? plz help me out in this..

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default why the while loop is not terminating? plz help me out in this..

    import java.util.*;
    import java.io.*;
    class close1
    {
    public static void main(String[] args) throws IOException
    {
    int p,q;
    BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
    System.out.println("enter values");
    String s1=br.readLine();
    p= Integer.parseInt(s1);
    String s2=br.readLine();
    q=Integer.parseInt(s2);
    close c1=new close();
    c1.find(p,q);
    }

    void find(int p,int q)
    {
    int ps;
    int s[]=new int[18];
    int lol,j,count=0,f=0,a;
    boolean b;
    for(lol=p;lol<=q;lol++)
    {
    j=0;

    while(lol>0) /*why this loop is not terminating?*/
    {

    ps= lol%10;
    j++;
    lol = lol/10;
    System.out.println(lol);

    }


    b= compare(s,j);
    if(b==true)
    count++;
    }
    int diff= q-p-count+1;
    System.out.println(diff);
    }
    public boolean compare(int[] s,int j)

    {System.out.print(s.length);
    try
    {
    int y,z,count=1;
    for(y=0;y<j-1;y++)
    {
    for(z=y+1;z<j-1;y++)
    {
    if(s[y]==s[z])
    {count++;
    if(count>3)
    {return true;
    }
    }
    }
    }}
    catch(Exception e)
    {e.getCause();
    }
    return false;
    }}


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: why the while loop is not terminating? plz help me out in this..

    Once is enough, twice is too many - your second post has been removed. Please read the link in my signature on getting help, it contains valuable information that might help you receive help faster

  3. #3
    Member
    Join Date
    Dec 2011
    Location
    United States
    Posts
    94
    My Mood
    Amused
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default Re: why the while loop is not terminating? plz help me out in this..

    This is my opinion on unterminating loops. They are simply infinite loops. Check your condition as you review your code and you will most likely find your problem hidden there. Fix it and move on.

  4. #4
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: why the while loop is not terminating? plz help me out in this..

    Quote Originally Posted by elisha.java View Post
    This is my opinion on unterminating loops. They are simply infinite loops. Check your condition as you review your code and you will most likely find your problem hidden there. Fix it and move on.
    What's the purpose of bumping old threads?
    Last post on this thread was made on October 20, 2011 and you didn't even bother to read the thread's date. Neither you helped OP with any extra ordinary input that could help. Just saying few statements in many of your posts are not making you to help others. Try to view the latest topics that are being posted and try to help them. I hope you understand what i mean to say. I've been reading almost five to ten old threads bumped only by you. Watch it.

Similar Threads

  1. Converting a while loop to a for loop and a for loop to a while loop.
    By awesom in forum Loops & Control Statements
    Replies: 3
    Last Post: February 26th, 2012, 08:57 PM
  2. [SOLVED] My while loop has run into an infinite loop...?
    By kari4848 in forum Loops & Control Statements
    Replies: 3
    Last Post: March 1st, 2011, 12:05 PM
  3. for loop and while loop problems
    By Pulse_Irl in forum Loops & Control Statements
    Replies: 4
    Last Post: May 3rd, 2010, 02:09 AM
  4. [SOLVED] allow a new input, dicarding the last mismatch input without terminating the program
    By voltaire in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 9th, 2010, 04:44 AM
  5. hi. i want to rewrite this do loop into a while loop.
    By etidd in forum Loops & Control Statements
    Replies: 3
    Last Post: January 26th, 2010, 05:27 PM