Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-14-2012, 09:10 PM   PM User | #1
shinju15
New to the CF scene

 
Join Date: Oct 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
shinju15 is an unknown quantity at this point
Loops validation not woorking - help

I'm trying to do a nested if inside a loop. The user has to enter a period between 5, 10, 15, 20, 25 years. Each year has a different rate and if the user enter a number that is not within these numbers the question is ask again.

The program runs good but the nested do-while loop is not working. If you see the condition of the while then 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. And if you type 0 it ends the progam. The validation it's not working and I don't not why.

I alredy tried to change the && for ||

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

{
//Declare variables
double principal, rate=0;
int mortgageTerm;

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();

if (mortgageTerm==1)
{
rate=0.035;
}
else if (mortgageTerm==2)
{
rate=0.039;
}
else if (mortgageTerm==3)
{
rate=0.044;
}
else if (mortgageTerm==5)
{
rate=0.05;
}
else if (mortgageTerm==10)
{
rate=0.060;
}


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




}while (principal!=0);

}

}
shinju15 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:51 AM.


Advertisement
Log in to turn off these ads.