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: Need to format this!!

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Post 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
    Help please.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default 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.

  3. The Following User Says Thank You to GregBrannon For This Useful Post:

    Dtank123456 (February 7th, 2014)

  4. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    Dtank123456 (February 7th, 2014)

Similar Threads

  1. [SOLVED] IBM FORMAT
    By DIVYANG in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 19th, 2014, 10:36 AM
  2. How to use format outpout
    By mael331 in forum Java Theory & Questions
    Replies: 1
    Last Post: October 12th, 2011, 03:14 PM
  3. Help with some code format
    By Highlord in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 9th, 2011, 09:27 PM
  4. Format Problems
    By maximus20895 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 27th, 2010, 09:48 PM
  5. How to format?
    By maximus20895 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 15th, 2010, 01:07 PM