There was an error in the 13th line in the code below.
An error appears saying that }
is omitted, but it should not be done.
I'm going to print out rock-paper-scissors. Please give me courage.
import java.util.*;
class bsh.21.02.19 {
public static void main(String[] args) {
int user = 0, com;
user = inputMethod(user);
com = randomMethod();
System.out.println ("You are " + user + "") + (user + 1));
System.out.println ("Com is " + com + ""; + (com + 1));
judgeMethod(user, com);
}
static void judgeMethod(int user, int com) {
switch(user-com) {
case 2: case -1:
System.out.println ("Lost";
break;
case 1: case -2:
System.out.println ("I won";
break;
case 0:
System.out.println ("It's tied";
break;
}
}
static int randomMethod() {
int com = 0;
com = (int)(Math.random() * 3) + 1;
System.out.println("com = " + com);
checkRangeMethod(com);
return com;
}
static int inputMethod(int user) {
System.out.print ("Scissors (1), Rock (2), Beam (3)");
Scanner scanner = new Scanner(System.in);
String tmp = scanner.nextLine();
user = Integer.parseInt(tmp);
checkRangeMethod(user);
return user;
}
static void checkRangeMethod(int user) {
if(user < 1 || user > 3) {
System.out.println ("Please re-enter". : ");
System.exit(0);
}
}
}
I'm not familiar with Java, but the problem seems to be that the class name contains .
.
When I simply changed the class name and ran it, it ran without any problems.
© 2024 OneMinuteCode. All rights reserved.