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.
Step-by-step 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);
}
}