软件工程个人作业01
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了软件工程个人作业01相关的知识,希望对你有一定的参考价值。
1.程序设计思想
引用Random类,先设置3个随机数,其中1个为运算符随机数,另外两个为0到99的整数随机数,进行整数的四则运算。再设置3个随机数,其中一个为运算符随机数,另外两个为0到99的整数随机数,前两个随机整数和后两个随机整数各组成一个真分数,进行真分数的四则运算。一个最大外循环,循环次数为30次,得出30道题。
2.源程序代码
1 package ketang; 2 3 import java.util.Random; 4 5 public class SiZeYunSuan { 6 7 public static void main(String[] args) { 8 int a1,a2,a; 9 Random ran=new Random(); 10 for(int i=0;i<30;i++) 11 { 12 a=ran.nextInt(5); 13 a1=ran.nextInt(100); 14 a2=ran.nextInt(100); 15 if(a==0) 16 System.out.println(a1+" + "+a2+" ="); 17 if(a==1) 18 { 19 System.out.println(a1+" - "+a2+" ="); 20 } 21 if(a==2) 22 System.out.println(a1+" * "+a2+" ="); 23 if(a==3) 24 { 25 while(a2==0) 26 a2=ran.nextInt(100); 27 System.out.println(a1+" / "+a2+" ="); 28 } 29 if(a==4) 30 { 31 int aa,a3,a4; 32 aa=ran.nextInt(4); 33 a3=ran.nextInt(100); 34 a4=ran.nextInt(100); 35 if(aa==0) 36 { 37 if(a1<a2&&a3<a4) 38 System.out.println(a1+"/"+a2+" + "+a3+"/"+a4+" ="); 39 if(a1>a2&&a3>a4) 40 System.out.println(a2+"/"+a1+" + "+a4+"/"+a3+" ="); 41 if(a1>a2&&a3<a4) 42 System.out.println(a2+"/"+a1+" + "+a3+"/"+a4+" ="); 43 if(a1<a2&&a3>a4) 44 System.out.println(a1+"/"+a2+" + "+a4+"/"+a3+" ="); 45 if(a1<a2&&a3==a4) 46 System.out.println(a1+"/"+a2+" + "+a3+"/"+(a4+1)+" ="); 47 if(a1>a2&&a3==a4) 48 System.out.println(a2+"/"+a1+" + "+a3+"/"+(a4+1)+" ="); 49 if(a1==a2&&a3<a4) 50 System.out.println(a1+"/"+(a2+1)+" + "+a3+"/"+a4+" ="); 51 if(a1==a2&&a3>a4) 52 System.out.println(a1+"/"+(a2+1)+" + "+a4+"/"+a3+" ="); 53 if(a1==a2&&a3==a4) 54 System.out.println(a1+"/"+(a2+1)+" + "+a4+"/"+(a3+1)+" ="); 55 } 56 if(aa==1) 57 { 58 if(a1<a2&&a3<a4) 59 System.out.println(a1+"/"+a2+" - "+a3+"/"+a4+" ="); 60 if(a1>a2&&a3>a4) 61 System.out.println(a2+"/"+a1+" - "+a4+"/"+a3+" ="); 62 if(a1>a2&&a3<a4) 63 System.out.println(a2+"/"+a1+" - "+a3+"/"+a4+" ="); 64 if(a1<a2&&a3>a4) 65 System.out.println(a1+"/"+a2+" - "+a4+"/"+a3+" ="); 66 if(a1<a2&&a3==a4) 67 System.out.println(a1+"/"+a2+" - "+a3+"/"+(a4+1)+" ="); 68 if(a1>a2&&a3==a4) 69 System.out.println(a2+"/"+a1+" - "+a3+"/"+(a4+1)+" ="); 70 if(a1==a2&&a3<a4) 71 System.out.println(a1+"/"+(a2+1)+" - "+a3+"/"+a4+" ="); 72 if(a1==a2&&a3>a4) 73 System.out.println(a1+"/"+(a2+1)+" - "+a4+"/"+a3+" ="); 74 if(a1==a2&&a3==a4) 75 System.out.println(a1+"/"+(a2+1)+" - "+a4+"/"+(a3+1)+" ="); 76 } 77 if(aa==2) 78 { 79 if(a1<a2&&a3<a4) 80 System.out.println(a1+"/"+a2+" * "+a3+"/"+a4+" ="); 81 if(a1>a2&&a3>a4) 82 System.out.println(a2+"/"+a1+" * "+a4+"/"+a3+" ="); 83 if(a1>a2&&a3<a4) 84 System.out.println(a2+"/"+a1+" * "+a3+"/"+a4+" ="); 85 if(a1<a2&&a3>a4) 86 System.out.println(a1+"/"+a2+" * "+a4+"/"+a3+" ="); 87 if(a1<a2&&a3==a4) 88 System.out.println(a1+"/"+a2+" * "+a3+"/"+(a4+1)+" ="); 89 if(a1>a2&&a3==a4) 90 System.out.println(a2+"/"+a1+" * "+a3+"/"+(a4+1)+" ="); 91 if(a1==a2&&a3<a4) 92 System.out.println(a1+"/"+(a2+1)+" * "+a3+"/"+a4+" ="); 93 if(a1==a2&&a3>a4) 94 System.out.println(a1+"/"+(a2+1)+" * "+a4+"/"+a3+" ="); 95 if(a1==a2&&a3==a4) 96 System.out.println(a1+"/"+(a2+1)+" * "+a4+"/"+(a3+1)+" ="); 97 } 98 if(aa==3) 99 { 100 if(a1<a2&&a3<a4) 101 System.out.println(a1+"/"+a2+" / "+a3+"/"+a4+" ="); 102 if(a1>a2&&a3>a4) 103 System.out.println(a2+"/"+a1+" / "+a4+"/"+a3+" ="); 104 if(a1>a2&&a3<a4) 105 System.out.println(a2+"/"+a1+" / "+a3+"/"+a4+" ="); 106 if(a1<a2&&a3>a4) 107 System.out.println(a1+"/"+a2+" / "+a4+"/"+a3+" ="); 108 if(a1<a2&&a3==a4) 109 System.out.println(a1+"/"+a2+" / "+a3+"/"+(a4+1)+" ="); 110 if(a1>a2&&a3==a4) 111 System.out.println(a2+"/"+a1+" / "+a3+"/"+(a4+1)+" ="); 112 if(a1==a2&&a3<a4) 113 System.out.println(a1+"/"+(a2+1)+" / "+a3+"/"+a4+" ="); 114 if(a1==a2&&a3>a4) 115 System.out.println(a1+"/"+(a2+1)+" / "+a4+"/"+a3+" ="); 116 if(a1==a2&&a3==a4) 117 System.out.println(a1+"/"+(a2+1)+" / "+a4+"/"+(a3+1)+" ="); 118 } 119 120 } 121 } 122 } 123 124 }
3.运行结果截图
4.分析课上未完成原因
课上想的少,想的不周全。
以上是关于软件工程个人作业01的主要内容,如果未能解决你的问题,请参考以下文章