import java.util.Random;
import java.util.Scanner;
public class Dome1 {
public static void main(String[] args) {
String str = "abcdefghijklmnopqrstuvwxyz0123456789";
Random random = new Random();
Scanner scanner = new Scanner(System.in);
int n1 = 0; //正确的字数
int n2 = 0; //实际打的总数
long startTime = System.currentTimeMillis(); //将当前时间转为毫秒数
for (int i = 0; i < 5; i++) {
//生成50个随机字符
String s = "";
for (int j = 0; j < 50; j++) {
int n = random.nextInt(str.length());
s+=str.charAt(n);
}
System.out.println(s); //输出50个字符在控制台
//接收用户录入的内容
String context = scanner.nextLine();
n2+=context.length(); //打字的总数
//计算正确的字数
for (int j = 0; j < context.length(); j++) {
if (j>=s.length()) {
break;
}
if (context.charAt(j)==s.charAt(j)) {
n1++; //正确的字数
}
}
}
long endTime = System.currentTimeMillis();
//得到用了多少秒
long m = (endTime-startTime)/1000;
System.out.println("正确率:" + n1*100 / n2 + "%");
System.out.println("打字速度:" + n2 * 60 / m + "字/分钟");
}
}
?运行结果:
?
|