zoukankan      html  css  js  c++  java
  • 软件工程个人作业01

    设计思路:定义四个数组,其中两个用于算数,一个用于随机,根据其结果输出算法,最后一个用于随机整数运算还是分数运算

    package 课堂;
    import java.util.Random;
    
    public class sizeyusuan
    {
        static void fuhao(int value)
        {
            if(value == 0)
            {
                System.out.print(" + ");
            }
            if(value == 1)
            {
                System.out.print(" - ");
            }
            if(value == 2)
            {
                System.out.print(" * ");
            }
            if(value == 3)
            {
                System.out.print(" / ");
            }
        }
        public static void main(String args[])
        {
            int []Array = new int[30];int []Array1 = new int[30];
            int []judge = new int[30];int []Array2 = new int[30];
            for(int i = 0;i < 30;i++)
            {
                Array[i] = new Random().nextInt(100);
                Array1[i] = new Random().nextInt(100);
                Array2[i] = new Random().nextInt(4);
                judge[i] = new Random().nextInt(2);
            }
            for(int i = 0;i < 30;i++)
            {
                if(judge[i] == 0)
                {
                    while(Array2[i] == 3 && Array1[i] == 0)
                    {
                        Array1[i] = new Random().nextInt(100);
                        if(Array1[i] != 0)
                        {
                            break;
                        }
                    }
                    System.out.print(Array[i]);
                    fuhao(Array2[i]);
                    System.out.println(Array1[i] + " = ");
                }
                if(judge[i] == 1)
                {
                    int a = new Random().nextInt(100);
                    int b = new Random().nextInt(100);
                        
                    while(Array2[i] == 3)
                    {
                        if(Array1[i] == 0)
                        {
                            Array1[i] = new Random().nextInt(100);
                        }
                        if(b == 0)
                        {
                            b = new Random().nextInt(100);
                        }
                        if(Array[i] != 0 && b != 0)
                        {
                            break;
                        }
                    }
                    
                    if(Array[i] > Array1[i])
                    {
                        int t = Array[i];
                        Array[i] = Array1[i];
                        Array[i] = t;
                    }
                    if(a > b)
                    {
                        int t = a;
                        a = b;
                        b = t;
                    }
                    
                    System.out.print("(" + Array[i] + "/" + Array1[i] + ")");
                    fuhao(Array2[i]);
                    System.out.println("(" + a + "/" + b + ") = ");
                }
            }
        }
    }



    课上未完成的原因。
      没有优化,数组超出范围。
  • 相关阅读:
    MongoDB安装&启动
    MongoDB集群搭建
    树与二叉树
    git入门
    MongoDB Java Driver
    Spring整合Junit4
    SQL字符串的数字部分递增
    [求职经历反面教材]4周面试20家,面霸磨成面瘫,仅供初级程序员参考!
    简陋的信息采集方式
    由一个博问学到的SQL查询方法 (一道多对多关系查询的面试题)
  • 原文地址:https://www.cnblogs.com/shenshenxin/p/5266138.html
Copyright © 2011-2022 走看看