码迷,mamicode.com
首页 > 其他好文 > 详细

个人工作流程计应192六组许舒然

时间:2021-04-12 12:49:42      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:记录   break   ***   out   and   显示   random   next   ase   

package Szys;
import java.util.Random;
  import java.util.Scanner;
  public class szys {
     public static void main(String[] args) {
         int [][] arr=new int[10000][3];//存储生成的每个题目,避免重复出现
        int [] temp01=new int [3];
         Scanner in=new Scanner(技术图片System.in);
        System.out.println("*******随机生成指定数量四则运算系统******");
         System.out.println("请输入题量:");
        int m=in.nextInt();
        System.out.println("请选择一行显示多少题目:");
        int n=in.nextInt();
        int x=1,y=0,num1,num2,cmp;
         boolean flag=false;//定义布尔类型变量用来记录是否重复
         for (int i = 0; i < m; i++) {
             flag=false;
             Random r = new Random();//生成随机数
             int temp;
             num1 = r.nextInt(100)+1;
             num2 = r.nextInt(100)+1;//生成两数1~100以内,避免除0情况
             cmp=r.nextInt(4);//生成0~4,表示加减乘除            
             temp01[0]=num1;//用temp01数组存储随机生成的三个数据           
             temp01[1]=num2;            
             temp01[2]=cmp;
            for(int j=0;j<y;j++) {//查重
                if(arr[j]==temp01) {
                     flag=true;        
                     break;
                 }
             }
            if(flag)//如果重复
                 continue;
             else//如果不重复,则存入数组
             {
                 arr[y][0]=num1;
                arr[y][1]=num2;
                 arr[y][2]=cmp;
                 y++;
                 switch(cmp) {
                 case 0://加
                    System.out.print("第"+x+"个题目:"+num1+"+"+num2+"=   ");        
                     break;
                 case 1://减
                    if(num1<num2) {
                         temp=num1;
                         num1=num2;
                        num2=temp;
                     }
                     System.out.print("第"+x+"个题目:"+num1+"-"+num2+"=    ");
                    break;
                 case 2://乘
                     if(num1<num2) {
                         temp=num1;
                         num1=num2;
                         num2=temp;
                    }
                     while(num1*num2>=100)
                         num1--;
                   System.out.print("第"+x+"个题目:"+num1+"*"+num2+"=    ");
                case 3:
                     if(num1<num2) {
                        temp=num1;
                         num1=num2;
                         num2=temp;
                    }
                     while(num1%num2!=0)
                         num2--;
                     System.out.print("第"+x+"个题目:"+num1+"/"+num2+"=    ");
                     break;
                 }
                 if(x%n==0)//换行
                     System.out.println();
                 x++;
             }
         }
     }
 }

个人工作流程计应192六组许舒然

标签:记录   break   ***   out   and   显示   random   next   ase   

原文地址:https://www.cnblogs.com/4603a/p/14644581.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!