import java.util.Random;
import java.util.Scanner;
public class Calculator {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
//生成两个随机数
int i = new Random().nextInt(10)+1;
int j = new Random().nextInt(10)+1;
System.out.println("How much is "+i +" * " +j+" ?");
while(true){
int result = input.nextInt();
//判断如果输入结果等于两数相乘结果返回very good,然后continue继续循环
if(result == (i*j)){
System.out.println("very good!");
i = new Random().nextInt(10)+1;
j = new Random().nextInt(10)+1;
System.out.println("How much is "+i +" * " +j+" ?");
continue;
}
//如果小朋友玩累了,按0,即可跳出循环,结束该程序
else if(result == 0){
System.out.println("welcome to use");
break;
}
//如果不相等,就返回try again ,直到结果是对的,然后continue继续循环
else {
System.out.println("no,please try again!");
while(result == (i*j)){
continue;
}
}
}
}
}
|
|