Home>

I'm making two methods, and when I compile, most of the lines say "no class, interface or enum".
Since I am using VSC, the parentheses are red as shown in the picture, but I clicked to check if it corresponds.
Do you know why? Also, if you have any other information you would like, please let me know.

By the way, it's not beautiful because the program is done according to the specifications as a school assignment.
]

public static String jyanken (String cpu, String me) {
  String result;
  if (cpu.equals ("gu")) {
    if (me.equals ("gu")) {
      result = "d";
    }
    if (me.equals ("choki")) {
      result = "l";
    }
    if (me.equals ("pa")) {
      result = "w";
    }
  }
  if (cpu.equals ("choki")) {
    if (me.equals ("gu")) {
      result = "w";
    }
    if (me.equals ("choki")) {
      result = "d";
    }
    if (me.equals ("pa")) {
      result = "l";
    }
  }
  if (cpu.equals ("pa")) {
    if (me.equals ("gu")) {
      result = "l";
    }
    if (me.equals ("choki")) {
      result = "w";
    }
    if (me.equals ("pa")) {
      result = "d";
    }
  }
  return result;
}
public static void pon (String r) {
  if (r.equals ("w")) {
      win ++;
      System.out.println ("You win");
  }
  if (r.equals ("d")) {
      draw ++;
      System.out.println ("It's a draw");
  }
  if (r.equals ("l")) {
      lose ++;
      System.out.println ("You lose");
  }
}
Main.java: 1: error: class, interface, or enum expected
public static String jyanken (String cpu, String me) {
              ^ ^
Main.java: 3: error: class, interface, or enum expected
  if (cpu.equals ("gu")) {
  ^ ^
Main.java: 6: error: class, interface, or enum expected
    }
    ^ ^
Main.java: 9: error: class, interface, or enum expected
    }
    ^ ^
Main.java:12: error: class, interface, or enum expected
    }
    ^ ^
Main.java:17: error: class, interface, or enum expected
    }
    ^ ^
Main.java:20: error: class, interface, or enum expected
    }
    ^ ^
Main.java:23: error: class, interface, or enum expected
    }
    ^ ^
Main.java:28: error: class, interface, or enum expected
    }
    ^ ^
Main.java:31: error: class, interface, or enum expected
    }
    ^ ^
Main.java:34: error: class, interface, or enum expected
    }
    ^ ^
Main.java:37: error: class, interface, or enum expected
}
^ ^
Main.java:39: error: class, interface, or enum expected
public static void pon (String r) {
              ^ ^
Main.java:42: error: class, interface, or enum expected
      System.out.println ("You win");
      ^ ^
Main.java:43: error: class, interface, or enum expected
  }
  ^ ^
Main.java:46: error: class, interface, or enum expected
      System.out.println ("It's a draw");
      ^ ^
Main.java:47: error: class, interface, or enum expected
  }
  ^ ^
Main.java:50: error: class, interface, or enum expected
      System.out.println ("You lose");
      ^ ^
Main.java:51: error: class, interface, or enum expected
  }
  ^ ^
19 errors
  • Answer # 1

    The presented code suddenly has a method definition.

    public class XXX {
        public static String jyanken (String cpu, String me) {
            String result;
    }

    Please try to be.
    name of the classXXXPlease give an appropriate name to the part.

    In addition, the answer is based on the assumption that the question text is "not the one before and after the code".