如何编写打印年份和余额的循环?

时间:2017-11-15 01:40:49

标签: java

Scanner console = new Scanner(System.in);
System.out.println("Enter Starting Balance: ");
Double balance = Double.parseDouble(console.nextLine());
System.out.println("Enter Yearly Contribution: ");
Double cont = Double.parseDouble(console.nextLine());
System.out.println("Enter Average Return On Investment as %: ");
Double avg = Double.parseDouble(console.nextLine());
System.out.println("Enter Number of years: ");
int year = Integer.parseInt(console.nextLine());

double result1 = (balance + cont) * (1 + avg / 100);
double result2 = (result1 + cont) * (1 + avg / 100);

  year = 0;
    while (year <= year) {
        System.out.println("Year " + year + ": " + balance + "");
        year = year + 1;
        for (result2 = result2; result2 >= result2; result2 = result2 + result2) {
        }

//我知道循环是错误的,只是不确定编写它的最佳方法。

1 个答案:

答案 0 :(得分:-1)

所以如果没有很多细节,我写了这段代码,导致输出非常接近你提供的例子。根据需要修改它以匹配您想要的输出。

.ear