Need to format this!!

• February 7th, 2014, 08:10 AM
Dtank123456
Need to format this!!
Homework problem...
[Code Java]

import java.util.Scanner;

public class Prog3{

public static void main(String[] args) {

//intiate the Scanner
Scanner input = new Scanner(System.in);

//decalre loan amount
System.out.print("Enter Loan Amount: ");
double loanAmount = input.nextDouble();

//declare int NumOfYears
System.out.print("Number Of Years: ");
int NumOfYears = input.nextInt();

//declare annual interest rate
double AnnualInterestRate = 5; // intital

System.out.println("Interest Rate: \t Monthly Rate:\t Total Payment: \t");
//intial loop
while (AnnualInterestRate <= 8) //test
{
//Monthly
double MonthlyInterestRate = AnnualInterestRate/1200;

//Calculate monthly payment
double monthlyPayment = loanAmount * MonthlyInterestRate / (1 - (Math.pow(1 / (1 + MonthlyInterestRate), NumOfYears * 12)));

//calculate total payment
double totalPayment = monthlyPayment * 12 * NumOfYears;

//ouput of total, monthly, annual
System.out.print("Interest Rate: \t" + AnnualInterestRate + (" Monthly Rate: \t") + monthlyPayment + " Total Payment: \t" + totalPayment);
System.out.println();

// change

AnnualInterestRate += .125;

} //while
}//main
}// class
[/CODE]

I need to format to a few decimal places, but seriously just am not understanding how to format correctly. It's in a column of 3
• February 7th, 2014, 08:16 AM
GregBrannon
Re: Need to format this!!
Welcome to the Forum! Please read this topic to learn how to post code correctly and other useful tips for newcomers.

Recommend you check out the printf() method.
• February 7th, 2014, 08:17 AM
Norm
Re: Need to format this!!
See the printf() method or the DecimalFormat class for ways to format numeric data for printing.

Please edit your post and wrap your code with code tags:
[code=java]