练习要求:
1、
计算机随机产生两个60–100的整数,
计算出大减小的差
让用户输入自己计算的差
对比用户输入是否正确,正确提示“correct”,错误提示“wrong”
2、上题让用户连续做5题,统计对错各几题,然后结束程序
3、用户连续做对5题,才结束程序,统计用户共用时多少秒
package week2;
import java.util.Scanner;
public class yyykyy {
public static void main(String[] args) {
int i, x = 0, y = 0;
// for (i = 1; i <= 100; i++) {
// System.out.print((char) (65 + (int) (Math.random() * 26)) + " ");
// if (i % 10 == 0)
// System.out.println("");
// } //随机输出四位大写字母的验证码
for (i = 1; i <= 5; i++) {
int n, m, a;
n = 60 + (int) (Math.random() * 41);
m = 60 + (int) (Math.random() * 41);
a = n + m;
System.out.print(m + " + ");
System.out.println(n);
System.out.print("please input the result : ");
Scanner input = new Scanner(System.in);
int result = input.nextInt();
if (result == a) {
System.out.println("you r correct!!!");
x += 1;
} else {
System.out.println("you r wrong!!!");
y += 1;
}
}
System.out.println("right result : " + x);
System.out.println("wrong result : " + y);
}
}