1 Star 0 Fork 0

20165324hcj / java-besti-is-hcj

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Test.java 3.67 KB
一键复制 编辑 原始数据 按行查看 历史
20165324hcj 提交于 2018-04-21 10:46 . 20180421
import java.util.*;
public class Test {
public static void main(String[] args) {
System.out.println("输入测试题数目:");
Scanner sc=new Scanner(System.in);
int number=sc.nextInt();
double right = 0;
double wrong = 0;
for (int i = 0; i < number; i++) {
System.out.println("第"+(i+1)+"道题,请在下方输入答案:");
double op1=(int)(Math.random()*10);
double op2=(int)(Math.random()*10);
Random r3 = new Random();
int m = r3.nextInt(4);
char[] chs = {'+','-','*','/'};
String Operator = String.valueOf(chs[m]);
//生成题目
if(Operator.equals("+")){
System.out.println(op1+"+"+op2+"=");
boolean b = add(op1,op2);
if(b == true){
right++;System.out.println("right! ");
}
else{
wrong++;System.out.println("no ");
System.out.println("right answer: "+(op1+op2));
}
}
else if(Operator.equals("-")){
System.out.println(op1+"-"+op2+"=");
boolean b =minus(op1,op2);
if(b == true){
right++;System.out.println("right! ");
}
else{
wrong++;System.out.println("no ");
System.out.println("right answer: "+(op1-op2));
}
}
else if(Operator.equals("*")){
System.out.println(op1+"×"+op2+"=");
boolean b =times(op1,op2);
if(b == true){
right++;System.out.println("right! ");
}
else{
wrong++;System.out.println("no ");
System.out.println("right answer: "+(op1*op2));
}
}
else{
System.out.println(op1+"÷"+op2+"=");
boolean b =Div(op1,op2);
if(b == true){
right++;System.out.println("right! ");
}else{
wrong++;System.out.println("no ");
System.out.println("right answer: "+op1/op2);
}
}
}
System.out.println("做对了"+right+"道题.");
System.out.println("做错了"+wrong+"道题.");
System.out.println("正确率为"+(right/(wrong+right))*100+"%");
}
private static boolean add(double x,double y) {
Scanner sc = new Scanner(System.in);
double num1 = sc.nextDouble();
double result = x + y;
if(num1 == result){
return true;
}else{
return false;
}
}
private static boolean minus(double x,double y) {
Scanner sc = new Scanner(System.in);
double num1 = sc.nextDouble();
double result = x - y;
if(num1 == result){
return true;
}else{
return false;
}
}
private static boolean times (double x,double y) {
Scanner sc = new Scanner(System.in);
double num1 = sc.nextDouble();
double result = x * y;
if(num1 == result){
return true;
}else{
return false;
}
}
private static boolean Div(double x,double y) {
Scanner sc = new Scanner(System.in);
double num1 = sc.nextDouble();
double result =x/y;
if(num1 == result){
return true;
}else{
return false;
}
}
}
Java
1
https://gitee.com/hcj_20165324/java-besti-is-hcj.git
git@gitee.com:hcj_20165324/java-besti-is-hcj.git
hcj_20165324
java-besti-is-hcj
java-besti-is-hcj
master

搜索帮助