我必须打印出这个等式的5个未来值

时间:2016-04-01 21:01:57

标签: java formatting

代码和计算是正确的我只是无法弄清楚如何正确格式化

static void main(String[] args) {

 Scanner input = new Scanner(System.in);

 String inputString;

  char flag = 'c';


  while(flag =='c' || flag == 'C') {

 System.out.print("Enter your investment amount");

 double futurevalue=input.nextInt ();

 System.out.print("Enter the interest rate (%)");

 double interest = input.nextInt ();

 int i;
 for (i =0; i<=5; i++)
 futurevalue = futurevalue * (1 + (interest/100));

 System.out.printf("Your value is" + futurevalue);

 System.out.printf("Enter c to continue or any other key to quit: ");

 input.nextLine();

 inputString = input.nextLine();

 flag = inputString.charAt(0);
 }
 }
}

期间1%

1 505.00

2 510.05

3 515.15

4 520.30

5 525.51

这就是它需要的样子

1 个答案:

答案 0 :(得分:1)

我不确定你在找什么。如果您希望每个循环打印答案

CreateList(tmplist, treeView1);