Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8624217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:28:11+00:00 2026-06-12T07:28:11+00:00

I had to write this for a class project. I don’t get any errors

  • 0

I had to write this for a class project. I don’t get any errors when compiling, but the program won’t run when I attempt to execute it.

We have to write a program myRandomWalkers.java that takes two command-line arguments N and T. In each of T independent experiments, simulate a random walk of N steps and compute the squared distance. Output the mean squared distance (the average of the T squared distances).

I wrote the following:

public class myRandomWalkers {

    public static void main(String[] args) {

        int n= Integer.parseInt(args[0]);
        int t= Integer.parseInt(args[1]);
        int x= 0; // starting x position
        int y= 0; // starting y position
        int sum = 0; // for calculating mean square distance
        double r;

        int count = 0;
        while (count <= t)
        {
            for (int i=0; i<n; i++) {

                r= Math.random();
                if (r<=0.25) x++;
                else if(r<=0.50) x--;
                else if(r<=0.75) y++;
                else if(r<=1.0) y--;        

                int z = ((x*x) + (y*y));
                sum +=z;
            }
        }

        int average = (sum/t);
        System.out.println ("mean squared distance = " + average);
    }        
}

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:28:13+00:00Added an answer on June 12, 2026 at 7:28 am

    The output will depend on the arguments you pass to your program. However:

    • if count > t the while loop will not be executed
    • if count <= t the while loop will never end because you don’t increment count – you probably need to add a count++; somewhere in your while loop.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had a question regarding this program I was trying to write. fin =
So I had to write a program for a computer project for high school
For this assignment I had to create my own string class. I initially wrote
I am writing a program for a class and it needs to read/write to
I wrote this ISAPI filter to rewrite the URL because we had some sites
I've not had to write much batch file code in the past and I'm
Recently I had to write an oracle function, and the error ora-06575 popped up
I have experience with OCaml. You had to write a stub for every function
I just finished creating several models and a had to separately write all of
I had the idea to write a matrix division in Haskell as Muliply A*

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.