-1

The object of this program is to create a account program to indicate 2 questions per month. I recorded the month input, now the question is.. How do I write the loop to repeatedly ask the two questions and stop at the month the input number was set at?

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");




 } 
Relogical
  • 39
  • 1
  • 5
  • 4
    1) For better help sooner, post an [SSCCE](http://sscce.org/). 2) Use a consistent and logical indent for code blocks. The indentation of the code is intended to help people understand the program flow. – Andrew Thompson Jul 11 '13 at 17:40
  • 1
    I don't see any purpose for a nested loop in what you appear to be attempting to achieve. A nested loop is just a loop within another loop. Perhaps you are asking the wrong question? – bengoesboom Jul 11 '13 at 17:42
  • You will have to explain this one a bit better. As bengoesboom, I don't see where a nested for-loop would do any good. – Jokab Jul 11 '13 at 17:45
  • I rewrote the question to help be more specific, hope you can understand what I mean. Thanks – Relogical Jul 11 '13 at 17:48

1 Answers1

0

I think this is what you are looking for but it is difficult to tell...

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);

 } 
Pete B.
  • 3,188
  • 6
  • 25
  • 38
  • Quick question Pete, @ for(int count=0;count – Relogical Jul 11 '13 at 17:52
  • You seem to have a very poor understanding of a basic java construct. Perhaps you should study that. – Pete B. Jul 11 '13 at 17:53
  • Well Pete, I never wrote a nested loop and I'm learning how to understand the basic java construct more. Would like it if you explain to me that part so I can learn that. – Relogical Jul 11 '13 at 17:55
  • What you're asking for in the original question is not a nested loop. It is simply a single for loop. A nested for loop would be a for loop inside another for loop. This link should be helpful http://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html – Jokab Jul 11 '13 at 17:57
  • As far as I can tell, that there is no need for a nested loop. Nested loops are often used in 2 dimensional data such as a matrix. This is not the case in computing bank balances. – Pete B. Jul 11 '13 at 17:58
  • Oh! That explains it. I was looking for how do structure it and seeing a nested loop, I was thinking it was that form. Thanks Jokab – Relogical Jul 11 '13 at 17:59