import java.util.Random;
import java.util.Scanner;
public class RandNum2 {
public static int ProduceNum(int range){
Random random = new Random();
int b1 = random.nextBoolean() ? 1 : -1;
int b2 = random.nextBoolean() ? 1 : -1;
int b3 = random.nextBoolean() ? 1 : -1;
int a = random.nextInt(range) * b1;
int b = random.nextInt(range) * b2;
int c = random.nextInt(range) * b3;
System.out.print(a);
System.out.print(" " + b + " ");
System.out.println(c);
return a + b + c;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int rang;
int questionNum;
int errCount = 0;
System.out.println("输入您想做多少题:");
questionNum = scanner.nextInt();
System.out.println("输入最大的数:");
rang = scanner.nextInt();
System.out.println("\n开始喽。。");
long startTime = System.currentTimeMillis();
for (int i = 0; i < questionNum; i++) {
int randNum = ProduceNum(rang);
int scana = scanner.nextInt();
if (scana == randNum){
System.out.println("good" + '\n');
}
else {
System.out.println("errCount++" + '\n');
errCount += 1;
}
}
long endTime = System.currentTimeMillis();
long timeSecondsSpend = (endTime - startTime)/1000;
System.out.println("错误率:" + (double)errCount/questionNum * 100 + "%");
System.out.println("耗时:" + timeSecondsSpend + "s");
System.out.println("平均耗时:" + timeSecondsSpend / questionNum + "s/题");
}
}
运行实例:
。。。
错误率:10.0%
耗时:34s
平均耗时:3s/题
|