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
__ is/are the amount of blank space between lines of text in a paragraph
Natali [406]
Indents? Double Space? one of those
5 0
3 years ago
Read 2 more answers
A media file refers to what kind of file? A. Clip art
prohojiy [21]

Waveform Audio (.wav) is a common file format. Created by Microsoft and IBM, WAV was one of the first audio file types developed for the PC. WAV files are defined as lossless, meaning that files are large and complete; nothing has been lost.

your answer will be

<h2><em><u>C; image</u></em></h2>
5 0
3 years ago
Read 2 more answers
What could be a summary sentence or phrase that captures your writing experience?
Natasha2012 [34]

<u>Answer:</u>

<em>A summary sentence should brief the whole content “what so ever the length of the original content” may be. </em>

For example, if you take a story, <em>moral will be the good example of summary. </em>One another example is when the teacher taught concept in the classroom, in the last few minutes of the class the teacher <em>would brief the whole into smaller points. </em>

Even nowadays, people go and visit movies only after seeing the review online. So once again the review is a small brief about the movie in one or two lines. <em>It should be crisp, use cherry-picked words, etc.</em>

3 0
2 years ago
List three types of cardinalities for relationships within a relational database.
Afina-wow [57]
This is about identifiers in a record referring to other records.
You can have many to one, one to one, many to many.

E.g., if you have two tables, Authors and Books, then a book record could have a reference to an author record. Since an author can write many books, this would be a many-to-one relationship.


3 0
2 years ago
Greg is the purchasing manager at a jeans-manufacturing company. He knows he could save his company money by using cheaper, thin
olasank [31]

Answer: B) Character

Explanation:

According to the question, character of Greg is depicted through the scenario as he is displaying his moral quality ,honesty and mind integrity through not providing low-quality product to his customers even though he has chance to save company money through buying shape material  .

Thus, he has good character to provide quality product and maintaining reputation and company as well as valuing his customers.                      

Other options are incorrect because fairness, community, expertise and competence are not the quality trait depicted through question's scenario. Thus, the correct option is option(B).

4 0
2 years ago
Other questions:
  • Sarah's research shows that business information management professionals also perform the duties of other professionals. Which
    9·1 answer
  • What is the post condition of an expression or variable
    11·1 answer
  • students at a camp can choose between boating and fishing in the morning and between hiking and horseback riding in the afternoo
    11·1 answer
  • True or false?
    13·1 answer
  • 0x400C (in hexadecimal)?
    8·1 answer
  • Yolanda first breaks down the whole game she needs to program into modules. She then breaks these modules into smaller modules u
    11·1 answer
  • Which of the following access control techniques allows the user to feel empowered and able to change security attributes?
    5·1 answer
  • Computer networks allow computers to send information to each other. What is the term used to describe the basic unit of data pa
    14·1 answer
  • Wilma is looking for facts about social media for her research project. What fact should she use for her project?
    15·1 answer
  • it is good to know and use the npsd framework while solution envisioning as part of the value discovery cycle. What is NPSD?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!