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
Use a while loop. Compare the digits; do not write a large if-else for all possible same-digit numbers (11, 22, 33, …, 88), as t
pav-90 [236]

Answer:

The solution code is written in Python 3:

  1. num = 11
  2. while(num <=88):
  3.    firstDigit = num // 10
  4.    secondDigit = num % 10
  5.    if(firstDigit == secondDigit):
  6.        print(num)
  7.        
  8.    num += 1

Explanation:

Firstly, create a variable, num, to hold the starting value, 11 (Line 1)

Create a while loop and set the loop condition to continue the loop while num smaller or equal to 88 (Line 3).

Within the loop, we can use // to perform the floor division and get the first digit of the num.  We use modulo operator % to get the second digit of the num. (Line 4 - 5)

If the firstDigit is equal to secondDigit, print the number (Line 7 -8). Lastly, increment the num by one and proceed to next iteration (Line 10).

5 0
3 years ago
Tasks you can perform online include which of the following?
nalin [4]

Answer:

k bhaneko hmm where ez the pic????????

8 0
3 years ago
Refer to the exhibit. A network administrator configures AAA authentication on router R1. The ACS servers are configured and run
oksian1 [2.3K]

Answer:

The correct answer for the following question is authentication process stops.

Explanation:

Authentication for the Telnet connection can be defined by the AAA method lists the AUTHEN. The AUTHEN lists define that first authentication methods is through the ACS servers by using a RADIUS protocols (or the RADIUS servers), and second authentication methods is use a local users database, and third methods is to use enable password. In the scenarios, however, the administrators fails to passes an authentication by first method, and the authentications processes stop and no the other authentications method are allowed.

3 0
3 years ago
Which of the following is said to occur when people receive more information than they can effectively​ process? A. Disinformati
egoroff_w [7]

Answer:

E. Information overload

Explanation:

Based on the information provided within the question it can be said that the term that is being described in this scenario is called Information Overload. This term refers to the difficulty that an individual may begin to experience in understanding and decision making after too much information about that issue has already been presented to them. Thus exceeding the quantity of daily information that the individual can handle (information overload).

6 0
3 years ago
Sorry to bother you guys but for some reason it wont let me comment. How can i fix this?
Step2247 [10]

Explanation:

I would just say close the app and come back in after

7 0
3 years ago
Read 2 more answers
Other questions:
  • Exactly how thin is the air in outer space?
    10·1 answer
  • Disk drives have been getting larger. Their capacity is now often given in terabytes (TB) where 1 TBequals1000 gigabytes, or abo
    14·1 answer
  • Sanford is creating an excel spreadsheet and needs to insert many worksheets to organize his data. What is the limit of the numb
    13·2 answers
  • EMERGENCYYYYY what does it mean when i get a security alert when i download an addon on google docs
    7·1 answer
  • Why do we need to measure the amperage of an electric current?​
    13·1 answer
  • The mode is least appropriate for:___________
    6·1 answer
  • Kahoot plzkahoot plzkahoot plz
    11·1 answer
  • Please Complete in Java a. Create a class named Book that has 5 fields variables: a stock number, author, title, price, and numb
    10·1 answer
  • What is 11100111 to decimal form?
    9·2 answers
  • the first thing to do when your computer gives you an error message is A restart the computer B press the F2 key C write down th
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!