package bao; /*import java.util.*; import java.io.*;*/ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.Random; import java.util.Scanner; public class hclszys { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("请输入要生成的题目数量:"); int num = sc.nextInt(); int number1; int number2; int symbol; File file = new File("E:\Eclipse\java作业\huanchongliusizeyunsuan\Text.txt"); //写入目标文件 try { FileWriter fw = new FileWriter(file); BufferedWriter bw = new BufferedWriter(fw); for(int i=1;i<=num;i++) { number1 = new Random().nextInt(100); number2 = new Random().nextInt(100); symbol = new Random().nextInt(4); double answer = 0; while(number2 == 0) number2 = new Random().nextInt(100); bw.write(i + "、 " + number1); switch(symbol) { case 0:bw.write(" + ");answer = number1 + number2;break; case 1:bw.write(" - ");answer = number1 - number2;break; case 2:bw.write(" × ");answer = number1 * number2;break; case 3:bw.write(" ÷ "); answer = (double)Math.round((double)number1/(double)number2*100)/100; break; } bw.write(number2 + " = " + answer); bw.newLine(); bw.write("***************************"); bw.newLine(); bw.flush(); } bw.close(); //从上层数据关流 /*fw.close();*/ FileReader fr = new FileReader(file); BufferedReader br = new BufferedReader(fr); Scanner sc1 = new Scanner(System.in); int all = 0, count = 0; String t = ""; double result; String str; while((str = br.readLine()) != null) { if(str.charAt(0)=='*'){ System.out.println("请输入答案"); Scanner an=new Scanner(System.in); char putAnswer = an.next().charAt(0); char[] answers = null; int i = 0; if(putAnswer==answers[i]){ int rightAnswer = 0; rightAnswer++; } i++; } all++; String[] a = str.split(" "); System.out.print(a[0] + a[1] + a[2] + a[3] + "="); result = sc1.nextDouble(); if(result == Integer.parseInt(a[5])) count ++; else t += a[0]; str = br.readLine(); System.out.println(str); } br.close(); System.out.println("共有" + all + "道题,做对了" + count + "道。"); if(t != "") System.out.println("做错的题有:" + t.substring(0, t.length())); } catch (IOException e) { e.printStackTrace(); } } }