• 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
  • 相关阅读:
    Android&Java面试题大全—金九银十面试必备
    android招聘啦,美图秀秀欢迎你加入!
    android经典源码,很不错的开源框架
    MongoDB、Hbase、Redis等NoSQL优劣势、应用场景
    体验go语言的风骚式编程
    金九银十中,看看这31道Android面试题
    android高级页面效果集锦
    flask中的request
    flask笔记(三)Flask 添加登陆验证装饰器报错,及解析
    flask笔记(二)
  • 原文地址:https://www.cnblogs.com/mitang0-0/p/10304865.html
Copyright © 2020-2023  润新知