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: java programming loop problem

  1. #1
    Member
    Join Date
    Oct 2012
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default java programming loop problem

    my problem is when i type NN to this code it ends my program..but i want that is i type more than one char it reloops again..
    help please thank you

            do{
        	System.out.print("\nDo You Want To Try Again? [Y/N]? ");
    			input = scan.next();
    			if(input.charAt(0) == 'n' || input.charAt(0) == 'N')
    				{
    				System.exit(0);
    			    }
        	  }while(!(input.charAt(0) == 'y' || input.charAt(0) == 'Y' || input.length() >= 2));
           }while(input.charAt(0) == 'y' || input.charAt(0) == 'Y' );
        	}
     
    	}


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: java programming loop problem

    if(input.charAt(0) == 'n' || input.charAt(0) == 'N')
    You are only checking the first character to == n or N. If you want to check something else you will have to check something else then. How would you check if more than one character was entered?

  3. #3
    Member
    Join Date
    Oct 2012
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java programming loop problem

    i have no idea how

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: java programming loop problem

    Well what else do you want to check for? There are multiple ways to do this. The point of the assignment is for you to choose a way that will work. Once you know how to do it, then write the code. If you can not get it tell us which way you chose and where you are stuck.

Similar Threads

  1. Java Programming Loop Execution Problem
    By Advent in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 14th, 2012, 04:20 PM
  2. Perfect Number Java Loop Problem - Please Help!?
    By Th3T3chGuy in forum Loops & Control Statements
    Replies: 2
    Last Post: November 13th, 2011, 05:09 PM
  3. Java applet programming problem
    By danielparry in forum What's Wrong With My Code?
    Replies: 8
    Last Post: March 4th, 2011, 10:31 AM
  4. Java Do..while loop problem
    By jwill22 in forum Loops & Control Statements
    Replies: 4
    Last Post: November 13th, 2010, 03:02 AM
  5. Java mailer programming code problem
    By shadeslayer88 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 1st, 2010, 01:21 AM