Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+14 votes

I am a bit confused to why in the program you end up needing to include:      

System.out.println("position = " + step);

statements with one in the while loop and one after it in the program? Anyone able to explain why?

asked in CSC211_Winter2018 by (269 points)

2 Answers

+9 votes

Well I didn't use step I just used one position as a variable. That it increments up and increments down. Its because position is a string because it is in quotes and the position or step in this case is a variable that you called.

answered by (8 points)
+8 votes

I agree with Evan. I would use a variable maybe named position which is initialized to zero and print that value out before the loop.

In the loop, as long as the position hasn't reached 3 or -3, generate a random number to decide whether to add 1 or subtract 1 from the position. then print the new position.

Use our basic algorigthm for finding a max to find the max position and print that value out after the loop.

answered by (3k points)
...