public class RandomWalkers { public static void main(String[] args) { int limite = Integer.parseInt(args[0]); int cicli = Integer.parseInt(args[1]); int totalePassi = 0; for (int i = 0; i < cicli; i++) { int x = 0; int y = 0; int passi = 0; 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++; } totalePassi += passi; } System.out.println("average number of steps = " + ((double) totalePassi / cicli)); } }