1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Tasya [4]
3 years ago
14

Two-dimensional random walk (20 points). A two-dimensional random walk simulates the behavior of a particle moving in a grid of

points. At each step, the random walker moves north, south, east, or west with probability equal to 1/4, independent of previous moves. Write a program RandomWalker.java that takes an int command-line argument n and simulates the motion of a random walk for n steps. Print the location at each step (including the starting point), treating the starting point as the origin (0, 0). Also, print the square of the final squared Euclidean distance from the origin as double. Note: you do not need arrays for this problem, just keep track of the x and y coordinates during the random walk.

Computers and Technology
1 answer:
natka813 [3]3 years ago
4 0

Answer:

The following code in the explanation does the job for you. Here I have made use of Random class of Java to generate random numbers.

Explanation:

Code:

import java.util.*;

class RandomWalker {

  public static void main(String args[]){

      int n = Integer.parseInt(args[0]);

      int x = 0;

      int y = 0;

      Random random = new Random();

      for(int i = 0; i < n; i++){

          int tmp = random.nextInt(4);

          if(tmp == 0){

              x++;

          }

          if(tmp == 1){

              y++;

          }

          if(tmp == 2){

              y--;

          }

          if(tmp == 3){

              x--;

          }

          System.out.println("(" + x + "," + y + ")");

      }

      int distance = x*x + y*y;

      System.out.println("Squared Distance = " + distance);

  }

}

You might be interested in
Virus warning don’t go on bit l y links it’s a virus
Alinara [238K]

Answer:

tysm

Explanation:

4 0
3 years ago
Read 2 more answers
"how do we store information in long term memory?"
Andru [333]

Answer:

By saving it in the hard drive.

Hope I helped!

8 0
3 years ago
What is the best definition of a network?
Cerrena [4.2K]

Answer:

C is the answer to this question.

3 0
2 years ago
Read 2 more answers
ZeroIt is a function that takes one argument and returns no value. The argument is a pointer to int. The function stores the val
Sedbober [7]

Answer:

zeroIt(&x);

Explanation:

The statement that sets the value stored in x to zero by invoking the function zerolt is given below

zeroIt(&x);

The zeroIt function is also given below for better understanding.

void zeroIt(int *x) {

   *x = 0;

}

As seen, the function takes an argument with integer variable type, which is a pointer, denoted by the asterisk symbol (*x).

The ampersan sign (&x) is used to access the variable whose value can then be stored.

7 0
3 years ago
Identifiy the impact of new technology for your organizations <br>​
Len [333]

Answer:

1)The Sleepwalker Effect. This effect has several dimensions. ...

2)The Transparency Effect. ...

3)The Black Box Effect. ...

4)The Splintering Effect.

7 0
2 years ago
Other questions:
  • In the Happy Valley School System, children are classified by age as follows: less than 2, ineligible 2, toddler 3-5, early chil
    6·1 answer
  • Your boss calls you from his home to use the vpn connection you configured for him on his laptop. he has traditionally depended
    6·1 answer
  • You've been hired as a consultant to help an online store owner. You need to complete the implementation of conversion tracking
    5·1 answer
  • Why should you not perform any personal grooming task while driving?
    5·2 answers
  • At an open or uncontrolled intersection, yield if ____.
    15·2 answers
  • Programming assignment (100 pts): In the C++ programming language write a program capable of playing Tic-Tac-Toe against the use
    14·1 answer
  • How can the function abcfunc change the address in its local copy of intpoint?
    11·1 answer
  • What is information associated with a document to help describe that document called?
    14·1 answer
  • D) Informal high level descuption of an algorithm in english kcalled
    9·2 answers
  • Susan wants to play the games that come with Windows on her computer, but they are not on the Start menu. What should she do in
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!