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
What is a data broker?
AleksAgata [21]

Answer:

The correct option is a.

A business that collects personal information about consumers and sells that information to other organizations.

Explanation:

Data brokers, also known as data suppliers, data fetchers, information brokers, or even data providers are businesses or companies (even individuals) that, on the most basic level, source and aggregate data and information (mostly information that are meant to be confidential or that are in the real sense difficult to get) and then resell them to third parties. These third parties could be other data brokers.  

They collect data and information from a wide range of resources and sources - offline and/or online e.g web access history, bank details, credit card information, official records (such as birth and marriage certificates, driver's licenses).  

Brokers can steal round about any information. Examples of information that brokers legally or illegally steal are full name, residential address, marital status, age, gender, national identification number, bank verification number. Brokers and hackers are siblings.

A couple types of data brokers are:

1. Those for fraud detection

2. Those for risk mitigation  

Hope this helps!

6 0
3 years ago
When solving for K, when cell potential is known, what is one of the first steps to follow?
BaLLatris [955]
Yes it is D like the other person said
5 0
3 years ago
What is software?
bogdanovich [222]

Answer:

B

Explanation:

3 0
3 years ago
Read 2 more answers
Why we need to measure the amperage of an electric current?​
Romashka [77]

Answer:

Explanation:It is very important to have a way to measure and quantify the flow of electrical current. When current flow is controlled it can be used to do useful work. The flow of electrons is measured in units called amperes. The term amps is often used for short

5 0
3 years ago
please write out an accurate code for the question below also please explain or I'll report you ( Thanks :) )
leva [86]

Answer: hmmmm i feel like u have to move the thingy thats shooting that light down 1 unit so it can move the planet.

Explanation: moving it down 1 unit will put it at the perfect angle to push the planet. :/

6 0
2 years ago
Read 2 more answers
Other questions:
  • One of the most famous ___ licenses is gpl, which ensures that a particular program remains free to distribute and allows its co
    10·1 answer
  • Select the correct answer.
    15·1 answer
  • Suppose that a company offers quantity discounts. If up to​ 1,000 units are​ purchased, the unit price is ​$1010​; if more than​
    7·1 answer
  • Which of the following is not a metamorphic agent?
    8·2 answers
  • Help me with this please
    5·1 answer
  • Determine whether or not the following pairs of predicates are unifiable. If they are, give the most-general unifier and show th
    13·1 answer
  • Binary is used to store what on a computer?<br> •Data<br> •Dates<br> •Address
    13·2 answers
  • What will be displayed in the console when this program runs?
    14·2 answers
  • Designers are comparing performance between a multi-core processor equipped with 16 in-order cores and a dual-core superscalar p
    13·1 answer
  • A(n) ___________ allows people at two or more locations to interact via two-way video and audio transmissions simultaneously as
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!