fork download
  1. public class RandomWalker {
  2. public static void main(String[] args) {
  3. int r = Integer.parseInt(args[0]);
  4. int steps = 0;
  5. int x = 0;
  6. int y = 0;
  7. double ar;
  8.  
  9. System.out.println("(" + x + ", " + y + ")");
  10.  
  11. while ((Math.abs(x) + Math.abs(y)) < r) {
  12. ar = Math.random();
  13.  
  14. if (ar < 0.25) x++;
  15. else if (ar < 0.50) x--;
  16. else if (ar < 0.75) y++;
  17. else if (ar < 1.00) y--;
  18.  
  19. System.out.println("(" + x + ", " + y + ")");
  20. steps++;
  21. }
  22. System.out.println("steps = " + steps);
  23. }
  24. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class RandomWalker is public, should be declared in a file named RandomWalker.java
public class RandomWalker {
       ^
1 error
stdout
Standard output is empty