Cristiano Magro
2025-10-05 0e284a3b0e031f2c6d59b12112df1a6c3bc5b289
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
public class RandomWalker {
    public static void main(String[] args) {
        int x = 0;
        int y = 0;
        int passi = 0;
        int limite = Integer.parseInt(args[0]);
 
        System.out.println("(" + x + "," + y + ")");
        while (Math.abs(x) + Math.abs(y) < limite) {
            double r = Math.random();
            if (r < 0.25) {
                x++;
            } else if (r < 0.5) {
                x--;
            } else if (r < 0.75) {
                y++;
            } else {
                y--;
            }
            passi++;
            System.out.println("(" + x + "," + y + ")");
        }
        System.out.println("steps = " + passi);
    }
}