• 软件工程个人作业01


    设计思想:先随机生成四个数,生成的概率都是一样的,所以三十道题的四则运算的数量差不多。

    源代码:

    整数:

    package 四则运算;
    import java.util.Random;
    
    public class Test 
    {
        public static void main(String[] args)
        {
            for(int i=0;i<30;i++)
            {
                int i1=new Random().nextInt(4);
                int i2,i3;
                if(i1==0)
                {
                    i2=new Random().nextInt(100)+1;
                    i3=new Random().nextInt(100)+1;
                    System.out.println(i2+"+"+i3+"=");
                }
                else if(i1==1)
                {
                    i2=new Random().nextInt(100)+1;
                    i3=new Random().nextInt(100)+1;
                    System.out.println(i2+"-"+i3+"=");
                }
                else if(i1==2)
                {
                    i2=new Random().nextInt(100)+1;
                    i3=new Random().nextInt(100)+1;
                    System.out.println(i2+"/"+i3+"=");
                }
                else if(i1==3)
                {
                    i2=new Random().nextInt(100)+1;
                    i3=new Random().nextInt(100)+1;
                    System.out.println(i2+"*"+i3+"=");
                }
            }
        }
    }

    分数:

    package 四则运算;
    import java.util.Random;
    
    public class Test1 
    {
        public static void main(String[] args)
        {
            for(int i=0;i<30;i++)
            {
                int i1=new Random().nextInt(4);
                int i2,i3;
                int i4,i5;
                if(i1==0)
                {
                    i2=new Random().nextInt(100)+1;
                    i3=new Random().nextInt(100)+1;
                    i4=new Random().nextInt(100)+1;
                    i5=new Random().nextInt(100)+1;
                    System.out.println(i2+"/"+i3+"+"+i4+"/"+i5+"=");
                }
                else if(i1==1)
                {
                    i2=new Random().nextInt(100)+1;
                    i3=new Random().nextInt(100)+1;
                    i4=new Random().nextInt(100)+1;
                    i5=new Random().nextInt(100)+1;
                    System.out.println(i2+"/"+i3+"-"+i4+"/"+i5+"=");
                }
                else if(i1==2)
                {
                    i2=new Random().nextInt(100)+1;
                    i3=new Random().nextInt(100)+1;
                    i4=new Random().nextInt(100)+1;
                    i5=new Random().nextInt(100)+1;
                    System.out.println(i2+"/"+i3+"*"+i4+"/"+i5+"=");
                }
                else if(i1==3)
                {
                    i2=new Random().nextInt(100)+1;
                    i3=new Random().nextInt(100)+1;
                    i4=new Random().nextInt(100)+1;
                    i5=new Random().nextInt(100)+1;
                    System.out.println(i2+"/"+i3+"/"+i4+"/"+i5+"=");
                }
            }
        }
    }

    截图:

  • 相关阅读:
    shell命令运行符号&、;、&&区别
    绕过CDN查看真实IP的有效方法
    kali Linux各历史版本
    Referer详解
    HttpServletResponse详解
    XML中保留字符及实体引用
    PreparedStatement用法详解
    Abnormal build process termination IDEA启动报错
    解决stackOverflow打开慢的问题
    git报错---If no other git process is currently running...
  • 原文地址:https://www.cnblogs.com/a1264393659/p/5268454.html
Copyright © 2020-2023  润新知