编写Java程序,显示五个加减法测验的正确率和用时
来源:互联网 发布:linux 宕机日志 编辑:程序博客网 时间:2024/06/12 14:48
代码如下:
package com.nfsbbs.test;import java.util.Scanner;public class MathsTest {public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int MAX = 20; final int MUST_SOLVE = 5; int a, b; double crt = 0; double rate; double startTime, endTime; double sec; System.out.println("Maths Test\n"); System.out.println("You need to correctly solve addition problems as quickly as you can. "); System.out.println("You must answer " + MUST_SOLVE + " correctly before the test will end. "); System.out.println("The operand values will be between 1 and " + MAX + ". \n"); System.out.println("Press ENTER to start the test. "); sc.nextLine(); startTime = System.currentTimeMillis(); for(int solve = 1; solve <= MUST_SOLVE; solve++) { a = (int) (Math.random() * MAX + 1); b = (int) (Math.random() * MAX + 1); System.out.println("\nWhat is " + a + " + " + b + "? "); if(sc.nextInt() == (a + b)) { System.out.println("CORRECT! "); crt++; } else { System.out.println("WRONG! "); } } rate =crt / MUST_SOLVE * 100; endTime = System.currentTimeMillis(); sec = (endTime - startTime) / 1000; System.out.println("\n\nYour rating is " + rate + "%. \nAnd you took " + sec + " sceonds. "); System.out.println("\nSee you next time. ");}}
输出:
Maths TestYou need to correctly solve addition problems as quickly as you can. You must answer 5 correctly before the test will end. The operand values will be between 1 and 20. Press ENTER to start the test. What is 6 + 6? 12CORRECT! What is 4 + 20? 24CORRECT! What is 5 + 9? 14CORRECT! What is 10 + 4? 14CORRECT! What is 2 + 13? 21WRONG! Your rating is 80.0%. And you took 10.419 sceonds. See you next time.
阅读全文
0 0
- 编写Java程序,显示五个加减法测验的正确率和用时
- C++ 小学生加减法测验程序源代码
- java计算程序用时
- 编写一个显示“欢迎学习Java"的Java Applet程序
- 编写一个显示“欢迎学习Java”的Java Applet程序
- java关于打字校验正确率的实现
- 用 C 语言编写 Windows 服务程序的五个步骤
- 用 C 语言编写 Windows 服务程序的五个步骤
- 用C语言编写Windows服务程序的五个步骤
- 用 C 语言编写 Windows 服务程序的五个步骤
- 用C编写Windows服务程序的五个步骤
- 用C编写Windows服务程序的五个步骤
- 用C 语言编写 Windows 服务程序的五个步骤
- 用C语言编写Windows服务程序的五个步骤
- 用C语言编写Windows服务程序的五个步骤
- 用C语言编写Windows服务程序的五个步骤
- 用C语言编写Windows服务程序的五个步骤
- 用C编写Windows服务程序的五个步骤
- Sublime Text的配置
- WP Super Cache 安装与设置详解
- 常见排序算法及其C语言实现(二)
- RecyclerView 之通用适配
- 动态规划基本问题
- 编写Java程序,显示五个加减法测验的正确率和用时
- 动态规划(三.LCS)
- intent的使用
- 简单记录spring在控制台向页面传參的几种方法
- Linux 常用查看日志命令
- 图像语义分割(1)- FCN
- centos7搭建hadoop集群
- Map四种遍历方式以及增删改查方法总结
- 双向循环链表