• Java——自动生成30道四则运算---18.09.27


    package chuti;
    import java.io.PrintWriter;
    import java.util.Scanner;
    import java.io.FileNotFoundException;
    class Counter
    {
        private int a;
        private int b;
         public int  add(int a,int b)
         {
             return a+b;
         }
         public int   reduce(int a,int b)
         {
             return a-b;
         }
         public int   multiplication(int a,int b)
         {
             return a*b;
         }
         public int   division(int a,int b)
         {
             if(b!=0)
             return a/b;
             else return 0;
         }
        
    }
    public class Demo {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            Counter counter=new Counter();
            PrintWriter out = null;
            try {
                out = new PrintWriter("text.txt");
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            int sum = 0;
           
           
            for (int i = 1; i <=10; i++) {
                int a = (int) Math.round(Math.random() * 100);
                int b = (int) Math.round(Math.random() * 100);
                int m= (int) Math.round(Math.random() * 3);
               
               switch(m)
               {
               case 0:
                   System.out.println(i+": "+a+"/"+b+"=");
                  
                   while(b==0){  b = (int) Math.round(Math.random() * 100); }
                  
                int c0 = in.nextInt();
                out.println(a+"/"+b+"="+c0);
                if (c0 == counter.division(a, b)) {
                    sum += 10;
                    System.out.println("恭喜答案正确");
                }
                else {
                    System.out.println("抱歉,答案错误");
                }
               
                break;
               
               case 1:
                   System.out.println(i+": "+a+"*"+b+"=");
                   int c = in.nextInt();
                   out.println(a+"*"+b+"="+c);
                   if (c == counter.multiplication(a, b)) {
                       sum += 10;
                       System.out.println("恭喜答案正确");
                   }
                   else {
                       System.out.println("抱歉,答案错误");
                   }
                   break;
               case 2:
                   System.out.println(i+": "+a+"+"+b+"=");
                   int c1 = in.nextInt();
                   out.println(a+"+"+b+"="+c1);
                   if (c1 == counter.add(a, b)) {
                       sum += 10;
                       System.out.println("恭喜答案正确");
                   }
                   else {
                       System.out.println("抱歉,答案错误");
                   }
                  
                   break ;
               case 3:
                   System.out.println(i+": "+a+"-"+b+"=");
                   int c2 = in.nextInt();
                   out.println(a+"-"+b+"="+c2);
                   if (c2 == counter.reduce(a, b)) {
                       sum += 10;
                       System.out.println("恭喜答案正确");
                   }
                   else {
                       System.out.println("抱歉,答案错误");
                   }
                   break ;
                   }
       
              }
            System.out.println("成绩"+sum);
            out.println("成绩:"+sum);
             out.close();      
        }
    }
     
    这是一个出一个解答一个题,然后判断结束后再出下一个题,一共出30个题的代码。
    记得,后面还有一个web
  • 相关阅读:
    [bbk2908]第4集 Chapter 03 介绍RAC的体系结构
    [bbk3011]第8集 Chapter 05 介绍RAC安装过程概述
    [bbk3100]第7集 Chapter 04 介绍RAC中CVU工具的使用
    [bbk2907]第3集 Chapter 02 RAC的安装过程中需要注意的要点
    [bbk2905]第1集 Chapter 01 介绍RAC概述
    [bbk2906]第2集 Chapter 02 介绍RAC概述
    RAC之CRS架构简介
    NOIP普及组2017比赛总结
    struct和typedef
    KMP详解(转)
  • 原文地址:https://www.cnblogs.com/mitang0-0/p/10304865.html
Copyright © 2020-2023  润新知