public class S1P3 {
public static void main (String[] args) throws Exception{
int num1 = (int)(Math.round(Math.random()*10));
int num2 = (int)(Math.round(Math.random()*10));
int sign = (int)(Math.round(Math.random()*3));
int answer;
System.out.println("\n\n*****");
if(sign==0)
{
System.out.println(num1+" * "+num2);
answer = num1*num2;
}
else if(sign==1)
{
System.out.println(num1+" / "+num2);
answer = num1/num2;
}
else if(sign==1)
{
System.out.println(num1+" - "+num2);
answer = num1-num2;
}
else
{
System.out.println(num1+" % "+num2);
answer = num1%num2;
}
System.out.println("*****\n");
System.out.println("3 ...");
Thread.sleep(1000);
System.out.println("2 ...");
Thread.sleep(1000);
System.out.println("1 ...");
Thread.sleep(1000);
System.out.println("ANSWER: "+answer);
}
}
我不明白两个“else if”的符号如何等于 2。程序如何知道选择哪一个?因为 2 个选项等于 1,所以这是否意味着其中一个没有被使用?我用的书有错字吗?我可以使用一些澄清,谢谢!