fork download
  1. public class RandomWalker1 {
  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.  
  8. System.out.println("(" + x + ", " + y + ")");
  9.  
  10. while ((Math.abs(x) + Math.abs(y)) < r) {
  11. if (Math.random() > 0.75) {
  12. steps++;
  13. x++;
  14. System.out.println("(" + x + ", " + y + ")");
  15. continue;
  16. }
  17. if (Math.random() <= 0.75 && Math.random() > 0.50) {
  18. steps++;
  19. x--;
  20. System.out.println("(" + x + ", " + y + ")");
  21. continue;
  22. }
  23. if (Math.random() <= 0.50 && Math.random() > 0.25) {
  24. steps++;
  25. y++;
  26. System.out.println("(" + x + ", " + y + ")");
  27. continue;
  28. }
  29. if (Math.random() <= 0.25) {
  30. steps++;
  31. y--;
  32. System.out.println("(" + x + ", " + y + ")");
  33. }
  34. }
  35. System.out.println("steps = " + steps);
  36.  
  37. }
  38. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class RandomWalker1 is public, should be declared in a file named RandomWalker1.java
public class RandomWalker1 {
       ^
1 error
stdout
Standard output is empty