又重新整理了一下代码,想的比较简单,没有真正的实现真分数,往后再继续改进
package NM;import java.util.*;public class SurF { public static void main (String[] agrs){ Scanner sc=new Scanner(System.in); Random r=new Random(); int op= 0; int n = 0; double a,b,c,d; String[] s={"+","-","*","/"}; while(true){ System.out.println("选择功能:\n0.退出1.简单的加减乘除运算 2.含分数运算"); op= sc.nextInt(); if (0 == op) { break;} if (1 == op) { int count1=0,count2=0; System.out.println("请输入题目个数(5分/题):"); int num=sc.nextInt(); System.out.println("请输入算数范围:"); int min=sc.nextInt(); int max=sc.nextInt(); String[] ask=new String[num]; for(int i=0;i-11){ if(answer==a-b){ System.out.println("this is right!"); count1++; } else { System.out.println("this is wroing!"+"正确答案是:"+(a-b)); count2++; } } else{ a=(int)(Math.random()*(max-min)+min);; b=(int)(Math.random()*(max-min)+min);; if(answer==a-b){ System.out.println("this is right!"); count1++; } else { System.out.println("this is wroing!"+"正确答案是:"+(a-b)); count2++; } } } else if("*"==s[l]){ if(answer==a*b){ System.out.println("this is right!"); count1++; } else { System.out.println("this is wroing!"+"正确答案是:"+(a*b)); count2++; } } else if("/"==s[l]){ if(answer==a/b){ System.out.println("this is right!"); count1++; } else { System.out.println("this is wroing!"+"正确答案是:"+String.format("%.2f",a/b)); count2++; } } } System.out.println("此题对了:"+count1+" "+"错了:"+count2+" "+"得分为:"+5*count1); } else if (2 == op) { int count1=0,count2=0; double CountAnswer1,CountAnswer2,CountAnswer; System.out.println("请输入题目个数(5分/题):"); int num=sc.nextInt(); System.out.println("请输入算数范围:"); int min=sc.nextInt(); int max=sc.nextInt(); String[] ask=new String[num]; for(int i=0;i