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 3 of 3

Thread: HELPP!!!! - Java validation with nested loops

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

    Default HELPP!!!! - Java validation with nested loops

    The program runs good but the nested do-while loop is not working. If you see the condition of the while you can see that it have to be a validation and if it is not in the range of those numbers it has to ask the questions again. You can see that the principal do- while has to validate that principal is not equal to 0 if it is it goes out from the program

    I declare:

    import java.util.Scanner;
    import java.text.DecimalFormat;
    public class ACMEMORTGAGE
    {
    public static void main (String args [])

    {
    //Declare variables

    int mortgageTerm, principal;

    Scanner key=new Scanner(System.in);

    DecimalFormat decimalPlaces=new DecimalFormat("$0.00");
    do
    {
    System.out.print("Enter principal amount (0 to end program):");
    principal=key.nextInt();

    do

    {
    System.out.print("Enter mortgage amortization (1, 2, 3, 5, 10.):");
    mortgageTerm=key.nextInt();

    } while (mortgageTerm==1 || mortgageTerm==2 || mortgageTerm==3 || mortgageTerm==5 || mortgageTerm==10);



    }while (principal!=0);

    }

    }


  2. #2
    Junior Member
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: HELPP!!!! - Java validation with nested loops

    Hey hi,
    there should be a condition which checks for the principal value before the inner do while loop.
    so if user enters the 0 value for principle , it will not execute the inner do while loop and it will exit the program due to outer do while loop condition (principal !=0)

    currently what is happening is , if user enters 0 for principal then it still executes the inner do while loop since there is no check of principal value, then it comes out of the program since the outer do while condition is not satisfied.

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

    Default Re: HELPP!!!! - Java validation with nested loops

    Also please see the announcements page for information on the forum including the use of code tags.

Similar Threads

  1. Nested for loops
    By Fordy252 in forum Loops & Control Statements
    Replies: 2
    Last Post: December 8th, 2012, 11:43 PM
  2. Nested for loops and array
    By bryanboy in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 15th, 2011, 06:45 AM
  3. Using Nested Loops
    By m2msucks in forum Loops & Control Statements
    Replies: 7
    Last Post: November 5th, 2011, 08:05 PM
  4. [SOLVED] Nested Loops & Processing Strings
    By Usoda in forum What's Wrong With My Code?
    Replies: 20
    Last Post: October 20th, 2011, 08:15 PM
  5. Help with Nested Loops
    By Plural in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 23rd, 2010, 04:31 PM