fork download
  1. package com.mycompany;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. System.out.println("Let's get it started!");
  6. Turn t1;
  7. Turn t2;
  8. do {
  9. t1 = Turn.random();
  10. System.out.printf("Игрок 1 выбирает %s%n", t1.definition);
  11. t2 = Turn.random();
  12. System.out.printf("Игрок 2 выбирает %s%n", t2.definition);
  13. if (t1 == t2) {
  14. System.out.println("Ничья, повтор хода!");
  15. }
  16. } while (t1 == t2);
  17. if (Math.abs(t1.order - t2.order) == 2) {
  18. if (t1.order < t2.order) {
  19. t2.order -= 3;
  20. } else {
  21. t1.order -= 3;
  22. }
  23. }
  24. System.out.println(t1.order < t2.order ? "Игрок 1 побеждает!" : "Игрок 2 побеждает!");
  25. }
  26.  
  27. private enum Turn {
  28. ROCK(0, "Камень"),
  29. SCISSORS(1, "Ножницы"),
  30. PAPER(2, "Бумага");
  31. int order;
  32. String definition;
  33. Turn(int order, String definition) {
  34. this.order = order;
  35. this.definition = definition;
  36. }
  37. public static Turn random() {
  38. switch ((int)(Math.random() * 3)) {
  39. case 0: return ROCK;
  40. case 1: return SCISSORS;
  41. default: return PAPER;
  42. }
  43. }
  44. }
  45. }
  46.  
Runtime error #stdin #stdout #stderr 0.12s 321024KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: Could not find or load main class Main