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 + ") = ");
                }
            }
        }
    }



    课上未完成的原因。
      没有优化,数组超出范围。
  • 相关阅读:
    UVa LA 2965
    UVa LA 3695
    UVa LA 3029 City Game 状态拆分,最大子矩阵O(n2) 难度:2
    Uva LA 3177
    Uva LA 3902
    Uva 11520
    UVa Live 3635
    python学习笔记-day05 字典
    python学习笔记-day04 元组
    python学习笔记 day04 列表增删改查
  • 原文地址:https://www.cnblogs.com/shenshenxin/p/5266138.html
Copyright © 2011-2022 走看看