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
How does toothbrushes affect the world of technology?
Yuri [45]

Answer:

The invention of the toothbrush made a huge impact of society and people for many reasons. You should always brush your teeth and keep your mouth clean so you will have nice, white teeth, healthy gums, good breath, and just a clean mouth! Without the toothbrush, your mouth would be smelly, gross, and full of bacteria.Some of the different impact categories included acidification, climate change, eutrophication, human health, land use, resource use and water scarcity. The results concluded that the electric toothbrush had the greatest environmental impact in 15 out of the 16 categories with water scarcity being the exception.Using the electric toothbrush as an example, this article examines the growing acceptability of domestic health technologies that blur the traditional boundaries between health, aesthetics and consumption. By using empirical material from individual and household interviews about people's oral health practices, this research explores the relationships between an everyday artefact, its users and their environments. It investigates the ways in which oral health technologies do, or do not, become domesticated in the home environment. We conclude that the domestication of oral health technologies is not inevitable, with the electric toothbrush often becoming an ‘unstable object' in the domestic setting.

Explanation:

3 0
2 years ago
Read 2 more answers
onsider the following program: Peform a total of six exercises. Select one exercise from each of the following areas: hips and l
Leviafan [203]

Answer:

Beginner

Explanation:

A program like this is ideal for a beginning exerciser due to the high number of repetitions and the sets are not much.

Cheers

3 0
3 years ago
What are hard ware and software requirments in multimedia computer system
marishachu [46]

Answer:

Some hardware requirement: Monitor, keyboard, mouse, sound card, memory, processor, graphics display card. Some software requirement: Windows XP/Vista, Video for Windows, Quicktime.

Explanation:

BRAINLEST

4 0
3 years ago
Which was the first console with a programmable microprocessor and a ROM chip?
Mazyrski [523]
I believe it was Nintendo hope this helps 
5 0
3 years ago
Read 2 more answers
When a slide is inserted, it appears A. at the end of the presentation. B. before the selected slide. C. after the selected slid
padilas [110]
C. after the selected slide
8 0
3 years ago
Read 2 more answers
Other questions:
  • Blogs are typically written by large companies or organizations as a way to express formal, technical, or scholarly information
    5·2 answers
  • Assume the following variable definitions int a = 5, b = 12; double x = 3.4, z = 9.1. What are the values of the following expre
    7·1 answer
  • Which group on the sparkline tools design tab would you choose if you wanted to change the data source of the sparkline? (1 poin
    10·1 answer
  • Jeremy’s office is in an earthquake prone area. His web server is in his office. What step should he take to protect the data on
    5·1 answer
  • In some cases, certain Hyper-V guest operating system features do not function properly using the operating system's own device
    9·1 answer
  • Dust buildup inside a desktop PC case can be managed effectively by ____.
    7·2 answers
  • A user's computer will not boot. A technician notices four indicator lights on the backside of the
    8·1 answer
  • If you wanted to include a chart in the new slide you are getting ready to create, you would most likely
    9·1 answer
  • Help please! Coding!
    9·1 answer
  • The design of a blog refers to:
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!