困惑:嵌套“for”循环和

时间:2013-07-11 17:38:43

标签: java nested-loops class-method

该计划的目的是创建一个帐户程序,以指示每月2个问题。我记录了月份输入,现在的问题是..如何编写循环以反复询问这两个问题并在输入数字设置为月份时停止?

System.out.println("How many months had passed since the account was established?");
months = keyboard.nextInt();     



//count should be months, not sure how to word it from the month input.
int count=0; for(count=0;count<13;count++)
{ System.out.println("How much did you deposit this month?");

System.out.println("How much did you withdraw this month?");

System.out.println("Your monthly interest is");




 } 

1 个答案:

答案 0 :(得分:0)

我认为这就是你要找的东西,但很难说......

for(int count=0;count<months;count++) { 
  System.out.println("How much did you deposit this month?");
  deposit = scanner.nextDouble();

  System.out.println("How much did you withdraw this month?");
  withdraw = scanner.nextDouble();

  //Do the math here....

  System.out.println("Your monthly interest is" + result);

 }