import java.util.Scanner;
import java.util.Random;
public class random {
public static void main(String[] args) {
System.out.println("===== CS302 TOOL BOX =====");
System.out.println("T > COIN TOSS SIMULATOR");
System.out.println("G > GRADE ESTIMATOR");
System.out.println("C > COLOR CHALLENGE");
System.out.println("Q > QUIT");
System.out.print("Type code letter for your choices: ");
String Menuchoices = "TGCQ";
String initial_input = scanner.next();
String code_choice = initial_input.toUpperCase();
boolean code_letter;
if (code_choice.equals(Menuchoices.substring(0,1))
||code_choice.equals(Menuchoices.substring(1,2))
||code_choice.equals(Menuchoices.substring(2,3))
||code_choice.equals(Menuchoices.substring(3,4)));
{System.out.println("success");}
else {System.out.println("Failure");}
}
}
Eclipse不会允许我把这个else语句放进去。有什么想法吗?
答案 0 :(得分:10)
因为if语句结尾处有分号,请将其删除
if (code_choice.equals(Menuchoices.substring(0,1))
||code_choice.equals(Menuchoices.substring(1,2))
||code_choice.equals(Menuchoices.substring(2,3))
||code_choice.equals(Menuchoices.substring(3,4)));