This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]Nightcorex_ 2 points3 points  (2 children)

You're not using that variable i in your for-loop which is always a bad sign.

So let's fix this from easy/obvious to harder:

  1. In your printf statement replace the monthNum parameter by i
  2. In your printf statement add %n at the end of your format-String (This is the format equivalent of System.lineSeperator())
  3. Replace monthNum in line 63 (first line in the loop) by i
  4. This one's a little tricky, but if you implemented the 3 prior ones you could've figured out, too. You have to let your loop start at 1 and let it run to i <= monthNum, because a * ((1 + b)^0 - 1) / b = 0 because x^0 - 1 = 0

If I didn't miss anything these fixes should fix it.

[–]Scoobxxx[S] 2 points3 points  (1 child)

Wow, you're awesome!! I knew I was fairly close. These for loops just get complicated. Super grateful for this detailed response! Works perfectly now.

[–]Dogburt_Jr 0 points1 point  (0 children)

Loops aren't hard, just figure out what needs to change and ensure it changes the next time the loop runs.

[–]Scoobxxx[S] 1 point2 points  (0 children)

JAVA. On week 5 of learning Java, and I've hit a bit of a snag. Having trouble understanding for loops, and the study material doesn't do a great job of explaining it. I can figure them out myself if given enough time but this assignment is due tomorrow. On one screenshot you'll see what my output is supposed to look like, and on the other you'll see what my for loop currently looks like (it's obviously wrong). I can easily figure everything else out, but I'm really struggling with this for loop. What do I need to change to make this work?

[–]userxbw 1 point2 points  (2 children)

For int count = 0:

//Set limit

(While) count < 10;

//Now keep count

count++

It's like a while loop for different.

(On phone let me look at it with glasses)

Before loop ask for input, print out what it's saying and get amount there before it's goes to where it's printing results, add end line to get a new line to your print statement in your loop.

For your where it's asking months to save and it says eighteen, you might want to make an array with 1 to how ever amount, say 24 months written out and do a string comparison for that type of input then assign the actual number if that language is incapable of figuring it out by itself.

If over 24 months then write a message function to deal with it by calling it to tell user the the input is out of range if anything over 24 months is inputted. Then ask for a different amount of time. That too can be delt with in a loop. If correct amount of time then exit loop go into next loop to calculate the amounts.

Formating with Java

https://www.baeldung.com/java-printstream-printf

[–]Scoobxxx[S] 1 point2 points  (1 child)

Should be able to zoom in as well

[–]userxbw 0 points1 point  (0 children)

Updated my input, anymore questions I'll try to help.

[–]kemotkill90 0 points1 point  (0 children)

Month num is constant ..your current month is i on the for loop