Question: Java program Write a int method named randomWalk(int x) that performs a random one-dimensional walk, reporting each position reached and the maximum position reached during

Java program

Write a int method named randomWalk(int x) that performs a random one-dimensional walk, reporting each position reached and the maximum position reached during the walk.

To do a "random walk", you begin at position 0. Then, on each step, you should either increase or decrease the position by 1 (with equal probability). The walk stops when x or -x is reached.

It should then print out the steps and return the number of steps that it took.

Once your method works, make a main that calls your function for x = 30.

*********** Sample Output *********************************************************************************************

The output should look like this for randomWalk(10):

position = 0 position = 1 position = 0 position = -1 position = -2 position = -1 position = -2 position = -3 position = -4 position = -5 position = -4 position = -5 position = -6 position = -7 position = -8 position = -7 position = -8 position = -9 position = -10 Steps : 19

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!