import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.*;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.lang.Math;
import java.math.BigDecimal;
import java.io.IOException;
public class Get {
static int q;
static double s,s1;
    public static void Z_jia() throws IOException
    {
            System.out.println("小朋友 准备一下开始做加法题了");    
            File newFile = new File("C:\\Users\\xxoo\\Desktop\\123\\加法题.txt");
            FileOutputStream out = new FileOutputStream(newFile);
            for(int i=1;i<=10;i++)
            {
                
                String[] a=new String[5];    
                int  x=(int)(Math.random()*100);
                int  y=(int)(Math.random()*100);
                s=x+y;
                a[0]="+";
                a[1]="=";
                a[2]="\n答案是:";
                a[3]="\t";
                a[4]="*************";
                BigDecimal f1 = BigDecimal.valueOf(x);
                out.write(String.valueOf(f1).getBytes());//x
                out.write(String.valueOf(a[0]).getBytes());//+
                BigDecimal f2 = BigDecimal.valueOf(y);
                out.write(String.valueOf(f2).getBytes());//y
                out.write(String.valueOf(a[1]).getBytes());//=
                out.write(String.valueOf(a[3]).getBytes());//\t
                if(q==1)s=Math.abs(s);
                out.write(String.valueOf(a[2]).getBytes());
                BigDecimal f3 = BigDecimal.valueOf(s);
                out.write(String.valueOf(f3).getBytes());//s
                out.write(String.valueOf(a[3]).getBytes());//\t
                out.write(String.valueOf(a[4]).getBytes());//**********
                
            }
    }
    public static void Z_jian() throws IOException
    {
        System.out.println("开始做减法题了 小朋友们");
        File newFile = new File("C:\\Users\\xxoo\\Desktop\\123\\减法题.txt");
        FileOutputStream out = new FileOutputStream(newFile);
        for(int i=1;i<=10;i++)
        {
            
            String[] a=new String[5];
            a[0]="-";
            a[1]="=";
            a[2]="\n答案是:";
            a[3]="\t";
            a[4]="*************";
            int  x=(int)(Math.random()*100);
            int  y=(int)(Math.random()*100);
             s=x-y;
            BigDecimal f1 = BigDecimal.valueOf(x);
            out.write(String.valueOf(f1).getBytes());//x
            out.write(String.valueOf(a[0]).getBytes());//-
            BigDecimal f2 = BigDecimal.valueOf(y);
            out.write(String.valueOf(f2).getBytes());//y
            out.write(String.valueOf(a[1]).getBytes());//=
            out.write(String.valueOf(a[3]).getBytes());
            if(q==1)s=Math.abs(s);
            out.write(String.valueOf(a[2]).getBytes());
            BigDecimal f3 = BigDecimal.valueOf(s);
            out.write(String.valueOf(f3).getBytes());//s
            out.write(String.valueOf(a[3]).getBytes());//\t
            out.write(String.valueOf(a[4]).getBytes());//**********
        }
    }
    public static void Z_cheng() throws IOException
    {
        System.out.println("开始做乘法题了 小朋友们");
        File newFile = new File("C:\\Users\\xxoo\\Desktop\\123\\乘法题.txt");
        FileOutputStream out = new FileOutputStream(newFile);
        for(int i=1;i<=10;i++)
        {
            String[] a=new String[5];
            a[0]="*";
            a[1]="=";
            a[2]="\n答案是:";
            a[3]="\t";
            a[4]="*************";
            int  x=1+(int)(Math.random()*50);
            int  y=1+(int)(Math.random()*50);
             s=x*y;
            BigDecimal f1 = BigDecimal.valueOf(x);
            out.write(String.valueOf(f1).getBytes());//x
            out.write(String.valueOf(a[0]).getBytes());//*
            BigDecimal f2 = BigDecimal.valueOf(y);
            out.write(String.valueOf(f2).getBytes());//y
            out.write(String.valueOf(a[1]).getBytes());//=
            out.write(String.valueOf(a[3]).getBytes());
            out.write(String.valueOf(a[2]).getBytes());
            BigDecimal f3 = BigDecimal.valueOf(s);
            out.write(String.valueOf(f3).getBytes());//s
            out.write(String.valueOf(a[3]).getBytes());//\t
            out.write(String.valueOf(a[4]).getBytes());//**********
        }
    }
    public static void Z_chu() throws IOException
    {
        System.out.println("开始做除法题了 小朋友们");
        File newFile = new File("C:\\Users\\xxoo\\Desktop\\123\\除法题.txt");
        FileOutputStream out = new FileOutputStream(newFile);
        for(int i=1;i<=10;i++)
        {
            String[] a=new String[5];
            a[0]="/";
            a[1]="=";
            a[2]="\n答案是:";
            a[3]="\t";
            a[4]="*************";
            int  x=1+(int)(Math.random()*20);
            int  y=1+(int)(Math.random()*20);
            s=(double)x/y;
            BigDecimal f1 = BigDecimal.valueOf(x);
            out.write(String.valueOf(f1).getBytes());//x
            out.write(String.valueOf(a[0]).getBytes());// /
            BigDecimal f2 = BigDecimal.valueOf(y);
            out.write(String.valueOf(f2).getBytes());//y
            out.write(String.valueOf(a[1]).getBytes());//=
            out.write(String.valueOf(a[3]).getBytes());
            out.write(String.valueOf(a[2]).getBytes());
            BigDecimal f3 = BigDecimal.valueOf(s);
            out.write(String.valueOf(f3).getBytes());//s
            out.write(String.valueOf(a[3]).getBytes());//\t
            out.write(String.valueOf(a[4]).getBytes());//**********
        }
    }
    public static void main(String[]args) throws IOException 
    {
        System.out.println("请选择年纪  1-三年级以下  2-三年级以上");
        Scanner scan=new Scanner(System.in);
        q=scan.nextInt();int i=0,R=0;
        File newFile = new File("C:\\Users\\xxoo\\Desktop\\123\\一百到题.txt");
         FileOutputStream out = new FileOutputStream(newFile);
         System.out.println("****************************************************");
         System.out.println("加法题:");
       Z_jia();
       try {
           BufferedReader br=new BufferedReader(new FileReader("C:\\Users\\xxoo\\Desktop\\123\\加法题.txt"));
           String line="";
           double putAnswer;
           while((line = br.readLine()) != null){
               System.out.println(line);   
                    System.out.println("请输入答案");
                    Scanner an=new Scanner(System.in);
                   putAnswer=an.nextDouble();
                   if(putAnswer==s){
                    R++;
                   }
                   i++;
                
                
                    
                
       }
           System.out.println("总共答对"+R+"道题,得分是"+R*25);
            br.close();}
            catch(Exception e){
            System.out.println(e.toString());
            };
       System.out.println("****************************************************");
         System.out.println("减法题:");
       Z_jian();
       try {
           BufferedReader br=new BufferedReader(new FileReader("C:\\Users\\xxoo\\Desktop\\123\\减法题.txt"));
           String line="";
          double putAnswer;
           while((line = br.readLine()) != null){
               System.out.println(line);   
               System.out.println("请输入答案");
               Scanner an=new Scanner(System.in);
              putAnswer=an.nextDouble();
              if(putAnswer==s){
               R++;
              }
              i++;
           
       }
           System.out.println("总共答对"+R+"道题,得分是"+R*25);
            br.close();}
            catch(Exception e){
            System.out.println(e.toString());
            };
       System.out.println("****************************************************");
         System.out.println("乘法题:");
        Z_cheng();
        try {
               BufferedReader br=new BufferedReader(new FileReader("C:\\Users\\xxoo\\Desktop\\123\\乘法题.txt"));
               String line="";
               double putAnswer;
               while((line = br.readLine()) != null){
                   System.out.println(line);   
                   System.out.println("请输入答案");
                   Scanner an=new Scanner(System.in);
                  putAnswer=an.nextDouble();
                  if(putAnswer==s){
                   R++;
                  }
                  i++;
           }
               System.out.println("总共答对"+R+"道题,得分是"+R*25);
                br.close();}
                catch(Exception e){
                System.out.println(e.toString());
                };
        System.out.println("****************************************************");
         System.out.println("除法题:");
       Z_chu();
       try {
           BufferedReader br=new BufferedReader(new FileReader("C:\\Users\\xxoo\\Desktop\\123\\除法题.txt"));
           String line="";
           double putAnswer;
           while((line = br.readLine()) != null){
               System.out.println(line);   
               System.out.println("请输入答案");
               Scanner an=new Scanner(System.in);
              putAnswer=an.nextDouble();
              if(putAnswer==s){
               R++;
              }
              i++;
       }
           System.out.println("总共答对"+R+"道题,得分是"+R*25);
            br.close();}
            catch(Exception e){
            System.out.println(e.toString());
            };
        
        System.out.println("****************************************************");
        
        
        
    
        
    
    }
}

实验插入文本时一直会出现覆盖的现象,其中数据的输入和调用花费了大量的时间。

实验内容其实一点都不难,只是文本的调用让人头疼。