Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9181747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:23:36+00:00 2026-06-17T18:23:36+00:00

I’m currently working on a program that will calculate a simple interest rate and

  • 0

I’m currently working on a program that will calculate a simple interest rate and monthly payment taken from a loan. Although, I am running into one pretty big problem. I am trying to make it so that my principal value(see in code) is re-assigned the value of my new balance(see in code). Here is my code right now, I will explain in better detail under it:

import java.util.Scanner;


 public class Payments {

public static double principal;       //principal
public static double annualrate;     //annual interest rate
public static double p;             //monthly payment
public static double mr;           //monthly interest rate
public static double nb;          //new balance after monthly payments
public static double i;          //interest (monthly)
public static String spaces = "           "; //spaces for making clean columns
public static int months = 12;

public static void main(String[] args){

    Scanner input = new Scanner(System.in);

    System.out.println("Principal: $");
    principal  = input.nextDouble();

    System.out.println("Anual Interest Rate: ");
    annualrate = input.nextDouble();

    System.out.println("Monthly Payment: $");
    p = input.nextDouble();


    calculate();

}

public static void calculate() {
    mr = annualrate / 12;
    i = mr * p;
    nb = principal + i - p;





    System.out.print("Month     Principal Amt.        Interest       Payment         New Balance");
    System.out.println();
    System.out.println();

    for(int x = 1; nb > 0; nb = principal + i - p){

        System.out.println(x + spaces + p + spaces + i + "%" + spaces + "$"           + p + spaces + "$" + nb);
             p = (Double)null;
             p = nb;

         }

     }
 }

So as you can most likely see by the comments in the code, all of the variables are shown. Now, disregard the null and me casting it to a double because that was the last thing that I tried to do before asking you guys 🙂 anyways, my final question is, how can I go about re-assigning the value of principal to my new balance (nb)? Also, a side question, would a while-loop be better for this kind of program?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:23:37+00:00Added an answer on June 17, 2026 at 6:23 pm

    This has already been said in the comments, but the most immediate problem that I can see is in

    for(int x = 1; nb > 0; x++){
    

    your condition, nb > 0 will never ever change in that loop.

    This means 1 of 2 things

    • your loop won’t execute
    • your loop won’t exit (infinite loop)

    judging by how you’re calculating nb(new balance) I’m assuming that it’s going to be above 0 most of the time, and that your loop will never stop.

    As things are right now, I’m not entirely sure what you actually want to do in that for loop or whether you even want a for loop at all, as that part is unclear.


    what is the for loop supposed to do?

    it almost looks like you’re attempting to do something like

    for (int x = 1; principal > 0; x++)
    {
        principal += principal * monthlyInterestRate;
        principal -= payment;
    
        System.out.println("insert output here");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.