每月计算器以获得利息

发布于 2025-02-05 02:30:56 字数 946 浏览 1 评论 0原文

    import java.util.Scanner;    
    import java.text.DecimalFormat;
    public class FutureValues {
      public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
      DecimalFormat df = new DecimalFormat("0.00");
      System.out.println("Enter the present value: ");
      int value = input.nextInt();
      System.out.println("Enter annual interest rate: ");
      double rate = input.nextDouble();
      double newRate = rate / 1200;
      System.out.println("Enter the number of months: ");
      int months = input.nextInt();
      int i;
      for (i = 1; i <= months; i++) {      
          double newVal = value + (value * newRate);
          System.out.println("The future value after " + i + " month is " + newVal);
         
    }    
  }    
}    

我试图将其用于程序以将Newval更新为下一个每月存款,但它对我尝试的任何事情都无法使用。

例如。 “ 1个月后的未来价值为1004.79” “ 2个月后的未来价值为1009.61” 等等。我只是无法将其更新到下一个值。

    import java.util.Scanner;    
    import java.text.DecimalFormat;
    public class FutureValues {
      public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
      DecimalFormat df = new DecimalFormat("0.00");
      System.out.println("Enter the present value: ");
      int value = input.nextInt();
      System.out.println("Enter annual interest rate: ");
      double rate = input.nextDouble();
      double newRate = rate / 1200;
      System.out.println("Enter the number of months: ");
      int months = input.nextInt();
      int i;
      for (i = 1; i <= months; i++) {      
          double newVal = value + (value * newRate);
          System.out.println("The future value after " + i + " month is " + newVal);
         
    }    
  }    
}    

I'm trying to get this to program to update the newVal to the next monthly deposit but it won't work for anything I try.

eg. "The future value after 1 month is 1004.79"
"The future value after 2 months is 1009.61"
and so on and so forth. I just cannot get it to update to the next value.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆蝶 2025-02-12 02:30:56

NEWVAL的计算应在循环中完成。

    import java.util.Scanner;    
    import java.text.DecimalFormat;
    public class FutureValues {
      public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
      DecimalFormat df = new DecimalFormat("0.00");
      System.out.println("Enter the present value: ");
      int value = input.nextInt();
      System.out.println("Enter annual interest rate: ");
      double rate = input.nextDouble();
      double newRate = rate / 1200;
      System.out.println("Enter the number of months: ");
      int months = input.nextInt();
      for (int i = 1; i <= months; i++) {
          value = value + (value * newRate);
          System.out.println("The future value after " + i + " month is " + value);
         
    }    
  }    
}   

The Calculation of newVal should be done within the loop.

    import java.util.Scanner;    
    import java.text.DecimalFormat;
    public class FutureValues {
      public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
      DecimalFormat df = new DecimalFormat("0.00");
      System.out.println("Enter the present value: ");
      int value = input.nextInt();
      System.out.println("Enter annual interest rate: ");
      double rate = input.nextDouble();
      double newRate = rate / 1200;
      System.out.println("Enter the number of months: ");
      int months = input.nextInt();
      for (int i = 1; i <= months; i++) {
          value = value + (value * newRate);
          System.out.println("The future value after " + i + " month is " + value);
         
    }    
  }    
}   
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文