zoukankan      html  css  js  c++  java
  • 四则运算器

                            一家软件公司程序员二柱的小孩上了小学二年级,老师让家长每天出30道四则运算题目给小学生做。

    题目要求: 

    1、题目避免重复;

    2、可定制(数量/打印方式);

    3、可以控制下列参数: 是否有乘除法、是否有括号、 数值范围、加减有无负数、除法有无余数、否支持分数 (真分数, 假分数, …)、是否支持小数 (精确到多少位)、打印中每行的间隔可调整

    代码如下:

    package counter;
    import java.util.Random;
    import java.util.Scanner;
    public class counter1 {
        static Scanner in =new Scanner(System.in);
        public static void main(String[] args) {
            Random a=new Random();
            int x,y,num=0;
            boolean h=true;
            System.out.println("请输入题目数目,打印方式");
            x=in.nextInt();
            y=in.nextInt();
            int q[] = new int[100000];
            int w[] = new int[100000];
            int e[] = new int[100000];
            for(int i=0;i<x;) {
               h=true;
               int random1=a.nextInt(100);
               int random2=a.nextInt(100);
               int random3=a.nextInt(4);
               for(int j=0;j<num;j++)
                  {
                      if((random1==q[j])&&(random2==w[j])&&(random3==e[j]))
                          {
                             h=false;
                             break;
                             }
                  }
               if(h==false)
                   continue;
               if(random3==0) {
                           System.out.print((i+1)+"."+random1+"+"+random2+"="+"  ");
                           i++;
                    }
               if(random3==1) {
                   if(random1>random2) 
                   {
                       System.out.print((i+1)+"."+random1+"-"+random2+"="+"  ");
                       i++;
                    }
                   else if(random1<=random2)
                   {
                        System.out.print((i+1)+"."+random2+"-"+random1+"="+"  ");
                        i++;
                   }
               }
               if(random3==2) {
                   if((random1*random2)<100)
                   {
                    System.out.print((i+1)+"."+random1+"*"+random2+"="+"  ");
                    i++;
                    }
                   else continue;
                   }
               if(random3==3){
                    if((random2!=0)&&(random1%random2)==0) 
                    {
                       System.out.print((i+1)+"."+random1+"/"+random2+"="+"  ");
                       i++;
                    }
                    else continue;
               }
                q[num]=random1;
                w[num]=random2;
                e[num]=random3;
                num++;
                if(i%y==0)
                   System.out.println("");
                   }
               }
      }
    © 版权声明
    文章版权归作者所有,未经允许请勿转载。
    THE END
  • 相关阅读:
    解决PKIX:unable to find valid certification path to requested target 的问题
    Linux 上的常用文件传输方式介绍与比较
    用VNC远程图形化连接Linux桌面的配置方法
    红帽中出现”This system is not registered with RHN”的解决方案
    linux安装时出现your cpu does not support long mode的解决方法
    CentOS SSH配置
    es6扩展运算符及rest运算符总结
    es6解构赋值总结
    tortoisegit安装、clon、推送
    es6环境搭建
  • 原文地址:https://www.cnblogs.com/xp-thebest/p/11537126.html
Copyright © 2011-2022 走看看