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]
4 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]4 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
Which type of testing is used to test how well the system will perform with a workload?
lys-0071 [83]

Answer:

Performance Testing

Explanation:

The Correct option is - Performance Testing

Reason -

INTEGRATION TESTING is a level of software testing where individual units / components are combined and tested as a group. The purpose of this level of testing is to expose faults in the interaction between integrated units.

PERFORMANCE TESTING  is a testing measure that evaluates the speed, responsiveness and stability of a computer, network, software program or device under a workload.

UNIT TESTING is a type of software testing where individual units or components of a software are tested. The purpose is to validate that each unit of the software code performs as expected.

Acceptance testing, a testing technique performed to determine whether or not the software system has met the requirement specifications.

5 0
3 years ago
Wap to calculate area and circumference of a circle​
Rainbow [258]

Answer:

To calculate the area of circle πr^2 formula.

And,to calculate the circumference we can use 2πr formula.

5 0
3 years ago
Change the screen resolution so you can view more information on your screen. Use the resolution that enables you to fit the mos
Nezavi [6.7K]

Answer:

The answer to this question is given below in the explanation section.

Explanation:

My laptop's current screen resolution is (1366 by 768 recommended). When you change your screen resolution, your pc automatically suggests the recommended screen resolution that helps you to view more information on your screen and enable you to fit the most information on the screen while still being able to read the display.

To change the screen resolution, you need to go through from the following steps:

  1. Right-click on empty space of desktop.
  2. As you right-click, a list of options will open, select "display setting" among them
  3. A new setting window will get open, at the left of the window, among given option, click on the first option i.e "display"
  4. The content of the display setting gets open in the right area of the window. scroll down and find the "Scale and Layout"
  5. under scale and layout, you can change your screen resolution while selecting the different screen resolution. However, it is good to select the recommended screen resolution based on your screen size.
7 0
4 years ago
!! HELP PLZ !!
DochEvi [55]
I think it might be short range and long-term
3 0
3 years ago
Read 2 more answers
Graduating from college can boost your income 60% compared to high school graduates. An average high school graduate without a c
Aleksandr-060686 [28]

Answer: $2,240,000

Explanation:

If you multiply 35,000 by 1.6, you will get 56,000.

Then you multiply 56,000 by 40 and you will get $2,240,000.

8 0
3 years ago
Other questions:
  • While investigating the settings on your SOHO router, you find two IP addresses reported on the device’s routing table, which is
    15·1 answer
  • How do i fix my this??
    12·2 answers
  • Which of the following statements is correct? A. The columns will be listed in the results in the same order they are stored in
    7·1 answer
  • What are the two basic steps in communication
    9·1 answer
  • What the heck is a motherboard and why is my computer not working when i take it out
    14·1 answer
  • What is wrong with each of the following?
    6·1 answer
  • Compute the sum of the values in data_array, instead of using the sum() function. To do this, you must "accumulate" a result, wh
    6·1 answer
  • E) Point out the errors( if any) and correct them:-
    14·1 answer
  • What two things should you do before starting the design process
    8·1 answer
  • tiny electrical paths to connect everything together is called ? A. graphic card B. audio card C. CPU D. Motherboard
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!