zoukankan      html  css  js  c++  java
  • 小学四则运算自动生成程序

    
    
    import java.util.Random;
    import java.util.Scanner;
    
    class Suan1
    {
        public int x,y,c;
        public Random random=new Random();
        String m;
        public String shengcheng()
        {
            
             c=random.nextInt(4);
             String fuhao;
             x=random.nextInt(100);
             y=random.nextInt(100);
             if(c==0)
             {
                 fuhao="+";
             }
             else if(c==1)
             {
                 fuhao="-";
             }
             else if(c==2)
             {
                 fuhao="*";
             }
             else
             {
                 fuhao="/";
             }
             m=String.valueOf(x)+fuhao+String.valueOf(y);
             return m;
             
        }
        public void shuchu()
        {
            if(c==0)
            {
                System.out.println(x+"+"+y+"=");
            }
            else if(c==1)
            {
                if(x>=y)
                System.out.println(x+"-"+y+"=");
                else
                    System.out.println(y+"-"+x+"=");
            }
            else if(c==2)
            {
                if(x*y<100)
                {
                    System.out.println(x+"*"+y+"=");
                }
                else
                {
                    for(int i=0;;i++)
                    {
                        if(x*y<=100)
                        {
                            System.out.println(x+"*"+y+"=");
                            break;
                        }
                        else
                        {
                            y=random.nextInt(100);
                        }
                    
                    }
                }
            }
            else if(c==3)
            {
                for(int i=0;;i++)
                {
                if(y==0)
                {
                    y=random.nextInt();
                }
                else
                {
                    break;
                }
                }
                    System.out.println(x*y+"/"+y+"=");
                    
            }
        }
        public int jianyan(String a[],int s)
        {
           int flag=1;
           for(int i=0;i<s;i++)
           {
               if(m.equals(a[i]))
               {
                  System.out.println(m);
                  flag=0;
                  break;
               }
           }
           return flag;
        }
    }
    class Suan2
    {
        public int m,n,x,y,c;
        public Random random=new Random();
        String s;
        public String shengcheng()
        {
            c=random.nextInt(4);
            x=random.nextInt(50);
            y=random.nextInt(50);
            m=random.nextInt(50);
            n=random.nextInt(50);
            String fuhao;
            if(c==0)
             {
                 fuhao="+";
             }
             else if(c==1)
             {
                 fuhao="-";
             }
             else if(c==2)
             {
                 fuhao="*";
             }
             else
             {
                 fuhao="/";
             }
             s=String.valueOf(x)+fuhao+String.valueOf(y);
             return s;
        }
        public void shuchu()
        {
            for(int i=0;;i++)
            {
                if(x==0)
                {
                x=random.nextInt(50);
                }
                else
                {
                    break;
                }
            }
            for(int i=0;;i++)
            {
                if(y==0)
                {
                y=random.nextInt(50);
                }
                else
                {
                    break;
                }
            }
            for(int i=0;;i++)
            {
                if(m==0)
                {
                m=random.nextInt(50);
                }
                else
                {
                    break;
                }
            }
            for(int i=0;;i++)
            {
                if(n==0)
                {
                n=random.nextInt(50);
                }
                else
                {
                    break;
                }
            }
            if(c==0)
            {
                if(x>y&&m>n)
                {
                System.out.println(y+"/"+x+"  +  "+n+"/"+m+"=");
                }
                else if(x>y&&m<n)
                {
                    System.out.println(y+"/"+x+"  +  "+m+"/"+n+"=");
                }
                else if(x<y&&m>n)
                {
                    System.out.println(x+"/"+y+"  +  "+n+"/"+m+"=");
                }
                else
                {
                    System.out.println(x+"/"+y+"  +  "+m+"/"+n+"=");
                }
            }
            else if(c==1)
            {
                if(x>y&&m>n)
                {
                System.out.println(y+"/"+x+"  -  "+n+"/"+m+"=");
                }
                else if(x>y&&m<n)
                {
                    System.out.println(y+"/"+x+"  -  "+m+"/"+n+"=");
                }
                else if(x<y&&m>n)
                {
                    System.out.println(x+"/"+y+"  -  "+n+"/"+m+"=");
                }
                else
                {
                    System.out.println(x+"/"+y+"  -  "+m+"/"+n+"=");
                }
            }
            else if(c==2)
            {
                if(x>y&&m>n)
                {
                System.out.println(y+"/"+x+"  *  "+n+"/"+m+"=");
                }
                else if(x>y&&m<n)
                {
                    System.out.println(y+"/"+x+"  *  "+m+"/"+n+"=");
                }
                else if(x<y&&m>n)
                {
                    System.out.println(x+"/"+y+"  *  "+n+"/"+m+"=");
                }
                else
                {
                    System.out.println(x+"/"+y+"  *  "+m+"/"+n+"=");
                }
            }
            else
            {
                if(x>y&&m>n)
                {
                System.out.println(y+"/"+x+"  /  "+n+"/"+m+"=");
                }
                else if(x>y&&m<n)
                {
                    System.out.println(y+"/"+x+"  /  "+m+"/"+n+"=");
                }
                else if(x<y&&m>n)
                {
                    System.out.println(x+"/"+y+"  /  "+n+"/"+m+"=");
                }
                else
                {
                    System.out.println(x+"/"+y+"  /  "+m+"/"+n+"=");
                }
            }
        }
        public int jianyan(String a[],int l)
        {
             int flag=1;
               for(int i=0;i<l;i++)
               {
                   if(s.equals(a[i]))
                   {
                      System.out.println(m);
                      flag=0;
                      break;
                   }
               }
               return flag;
        }
    }
    public class Jisuan {
    
        public static void main(String[] args) {
            // TODO 自动生成的方法存根
            Random random=new Random();
            Suan1 a=new Suan1();
            Suan2 b=new Suan2();
            Scanner in=new Scanner(System.in);
            String shuju[]=new String[30];
            int flag=0;
            int m=0;
            for(int i=0;i<30;i++)
            {
                shuju[i]=new String();
            }
            
            for(int i=0;;i++)
            {
              System.out.println("1   整数的四则计算");
              System.out.println("2   真分数的四则计算");
              System.out.println("3   整数与真分数的混合四则运算");
              System.out.println("4   退出");
              System.out.println("请选择:");
              int t=in.nextInt();
              if(t==1)
              {
                while(m<30)
                 {
                        shuju[m]=a.shengcheng();
                        flag=a.jianyan(shuju, m);
                        if(flag==1)
                        {
                            a.shuchu();
                            m++;
                            flag=0;
                        }
                 }
                m=0;
              }
              else if(t==2)
              {
                  while(m<30)
                    {
                      shuju[m]=b.shengcheng();
                      flag=b.jianyan(shuju, m);
                        if(flag==1)
                        {
                            b.shuchu();
                            m++;
                            flag=0;
                        }
                    }
                  m=0;
              }
              else if(t==3)
              {
                  while(m<30)
                    {
                      int suiji=random.nextInt(2);
                      if(suiji==0)
                      {
                      shuju[m]=b.shengcheng();
                      flag=b.jianyan(shuju, m);
                        if(flag==1)
                        {
                            b.shuchu();
                            m++;
                            flag=0;
                        }
                      }
                      else
                      {
                          shuju[m]=a.shengcheng();
                            flag=a.jianyan(shuju, m);
                            if(flag==1)
                            {
                                a.shuchu();
                                m++;
                                flag=0;
                            }
                      }
                    }
                  m=0;
              }
              else
              {
                  break;
              }
            }
            
    
        }
    
    }
    
    
    















  • 相关阅读:
    libtorch初体验
    libtorch 常用api函数示例(史上最全、最详细)
    VS2015,vs2019用正则表达式搜索删除空白行的方法
    CMake引入opencv3.1.0编译时includes non-existent path问题解决
    opencv编译的时候的注意事项------如果出现 target glog::glog 找不到的情况,可能是由于glog的版本过低导致的。通常与ceres有关
    ID3D11Multithread 未声明的标识符 opencv 411 opencv400 3411 opencv440 vs2015 都出现这个错误 但是opencv311没有出现这个问题
    错误 LNK2001 无法解析的外部符号 "__declspec(dllimport) bool cv::__termination" (__imp_?__termination@cv@@3_NA) opencv_cudev
    raw.githubusercontent.com无法连接
    编译opencv3.1.0时出现错误:error: ‘NppiGraphcutState’ has not been declared
    Ubuntu16.04 安装g++6
  • 原文地址:https://www.cnblogs.com/zll20153246/p/6491997.html
Copyright © 2011-2022 走看看