that takes an integer N and simulates the motion of a random walker

for N steps. After each step, I am required to print the location of

the random walker, treating the origin position as(0,0).

Finally it asks to print the square of the distance from origin to the final point.

Although I have worked a little on this java problem. I cant seem to figure out

a method to print its location /final position after N step.

My code is here:

public class math { public static void main(String[] args) { int N= Integer.parseInt(args[0]); int M=Integer.parseInt(agrs[1]); for (int t = 0; t < N; t++) { int x = 0, y = 0; int[]a= new int[x][y]; // repeatedly take a random step, unless you've already escaped while (x >= -M && x <= M && y >= M && y <= M) { double r = Math.random(); if (r < 0.25) x++; else if (r < 0.50) x--; else if (r < 0.75) y++; else if (r < 1.00) y--; a[x][y]= true;

I would be extremely extremely grateful of your help. Please note this is not a homework asssignment.

This problem is from a book that I am using to learn java over summers. Thanks

Kind Regards,

Ahsan

*** Edit ***

Please use code tags when posting code.

This post has been edited by **GunnerInc**: 29 July 2012 - 08:50 AM

Reason for edit:: Added code tags