package 四则运算; import java.util.Random; import java.util.Scanner; import java.io.*; import java.io.BufferedReader; import java.io.FileReader; public class Szys { public static void main(String args[]) throws IOException{ FileOutputStream fos = new FileOutputStream("heweihao.txt"); Scanner scanner = new Scanner(new BufferedReader(new FileReader("heweihao.txt"))); PrintStream ps = null; scanner.useDelimiter("[|]"); ps = new PrintStream(fos); Scanner cin=new Scanner(System.in); Random random = new Random(); int q = 0; double sum[] = null; sum = new double[30]; for(int i=0;i<30;i++) { int a=random.nextInt(101); int b=random.nextInt(101); ps.print(a); int tatted; tatted=random.nextInt(3); if(tatted==0) { ps.print("+"); sum[q]=a+b; }else if(tatted==1) { ps.print("-"); sum[q]=a-b; }else if(tatted==2) { ps.print("*"); sum[q]=a*b; }else if(tatted==3) { ps.print("/"); sum[q]=a/b; } ps.print(b); ps.print("="); q++; if(i<29) { ps.println("|"); } } q=0; double sum1; int fenshu=0; while (scanner.hasNext()) { System.out.println(scanner.next()); System.out.println("请输入答案"); sum1=cin.nextDouble(); if(sum1==sum[q]) { System.out.println("答案正确"); fenshu++; }else { System.out.println("答案错误"); } q++; } System.out.println("总分数为:" + fenshu); cin.close(); ps.close(); scanner.close(); } }
这个代码是根据之前的代码加东西修改的,还是不太符合要求,我会再写一下的