Results 1 to 7 of 7
  1. #1
    damian is offline Member
    Join Date
    May 2013
    Posts
    9
    Rep Power
    0

    Default Cant find the problem in my program

    Java Code:
    void booking(int x)throws IOException
          {
              
              String str1="",str2="";int ag1=0;
              for(int i=0;i<x;i++)
              {
                  Loop5:
                  for(;;)
                  {System.out.println("Please enter name of person "+(i+1));
                  System.out.println("also enter the gender of the person ...separate the name and gender with a ','");
                  str1=buf.readLine( );
                  str1=str1.trim( );
                  
                  int c=str1.indexOf(",");
                  
                  if(c!=-1)
                  {String g=str1.substring(str1.indexOf(','));g=g.trim( );
                  if(g.equalsIgnoreCase("Male"))
                  {
                      break Loop5;
                    }
                    else if(g.equalsIgnoreCase("Female"))
                    {break Loop5;}
                    else 
                    { System.out.println("It seems u have not followed the instructions completely ");
                       System.out.println("Eg");
                       System.out.println("Damian,Male");
                       continue;}}
                    else
                    {
                  
                       System.out.println("It seems u have not followed the instructions completely ");
                       System.out.println("Eg");
                       System.out.println("Damian,Male");
                       continue;
                    }
                }
                  
                  
                  
                  
                  System.out.println("Enter the age of person");
                  ag1=Integer.parseInt(buf.readLine());
                 
                  
                  ag[i]=ag1;
                  aname[i]=str1;
                  
                }
              
               }

    i cant find the probem in the program please help
    Regd
    Damian
    Last edited by JosAH; 05-26-2013 at 11:51 AM. Reason: added [code] ... [/code] tags

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,729
    Blog Entries
    7
    Rep Power
    21

    Default Re: Cant find the problem in my program

    Quote Originally Posted by damian View Post
    i cant find the probem in the program please help
    What does it do that you don't want it to do or what doesn't it do that you want it to do? Please don't make us guess but clearly describe the problem.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    damian is offline Member
    Join Date
    May 2013
    Posts
    9
    Rep Power
    0

    Default Re: Cant find the problem in my program

    O sorry my bad
    i wanted to accept the name gender and age and store them in an array
    i decided to use substring and index of methods for it
    i told the user to enter the name then insert a ',' after which he/she could type in their gender
    if he doesnt to do so he would have to enter his name and gender again
    but the problem is that when i enter the name followed by the gender it tells me to enter it again

  4. #4
    damian is offline Member
    Join Date
    May 2013
    Posts
    9
    Rep Power
    0

    Default Re: Cant find the problem in my program

    oh and the the code runs perfectly without the gender code and the empty for loop

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,729
    Blog Entries
    7
    Rep Power
    21

    Default Re: Cant find the problem in my program

    Print the values of 'str1' and 'g' after your program has just read them, so you can see what your program is doing. It doesn't hurt if you print out other variable values as well.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    damian is offline Member
    Join Date
    May 2013
    Posts
    9
    Rep Power
    0

    Default Re: Cant find the problem in my program

    Thanks !!!
    it worked
    it included the ',' too hence the wrong o/p
    U are Awesoem
    thanks man

  7. #7
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,729
    Blog Entries
    7
    Rep Power
    21

    Default Re: Cant find the problem in my program

    Good; we don't need no steenkin' debuggers; System.out.println( ... ) is good enough and it's free. Especially in loops and tricky index operations it's great ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. My program can't find file, even it being there
    By Daniel Silvester in forum New To Java
    Replies: 8
    Last Post: 05-14-2013, 12:01 PM
  2. Replies: 4
    Last Post: 08-10-2012, 09:12 AM
  3. Can't find error in my program!
    By kkGG in forum New To Java
    Replies: 2
    Last Post: 11-10-2010, 06:38 PM
  4. Replies: 3
    Last Post: 09-26-2010, 07:29 AM
  5. SWT program on Linux can find jar files.
    By glmarsh in forum SWT / JFace
    Replies: 1
    Last Post: 07-20-2009, 08:02 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
  •