这是我的代码:
package santaclaus;
import java.util.*;
public class SantaClaus {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Have you been good this year? (1 = Yes, 2 = No)");
int good;
good = scan.nextInt();
System.out.println("Have you been naughty or nice?");
String naughtynice;
naughtynice = scan.nextLine();
if(good == 1 && "nice".equals(naughtynice)){
System.out.println("You will get presents from Santa Claus");
}else if(good == 2 && "naughty".equals(naughtynice)){
System.out.println("Your only getting coal this year");
}else if(good == 1 && "naughty".equals(naughtynice) || good == 2 && "nice".equals(naughtynice)){
System.out.println("You'll just have to wait to Christmas morning to see!");
}
}
}
当我运行时,我得到了这个:
run:
Have you been good this year? (1 = Yes, 2 = No)
1
Have you been naughty or nice?
BUILD SUCCESSFUL (total time: 1 second)
如何制作,以便我可以输入"顽皮或"很好"?然后让它进入if语句的东西?对不起,我不好意思:/