• 缓冲流四则运算


    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();
    
            }
    
    
            
            
        }
    
    }
  • 相关阅读:
    使用Bat自动打包并通过FTP发送到备份服务器——实战测试
    什么是STP
    【基础】华为单臂路由技术配置记录
    Windows Server 2012系统上安装.net framework3.5教程
    eNSP启动设备AR1失败记一次解决步骤
    Linux系统设置 SSH 通过密钥登录
    windows和linux修改ipv6和ipv4的优先级
    思科交换机配置中继
    【Nginx】Nginx反向代理转发Host设置
    idea查看类的uml图
  • 原文地址:https://www.cnblogs.com/baimafeima/p/9966949.html
Copyright © 2020-2023  润新知