zoukankan      html  css  js  c++  java
  • 随机生成300道四则运算

    package lianxi;

    import java.util.Random;

    public class Sizeyunsuan {
     public static void main(String args[]) {
           
            char f[] = { '+', '-', '*', '/' };
            int max=100;
            for (int i = 0; i < 300; i++) {
                Random random = new Random();
                int a = random.nextInt(max+1);
                int b = random.nextInt(max+1);
                int c = random.nextInt(4);
                int result=-1;
                switch (c) {
                case 0:
                    result=a+b;
                    break;
                case 1:
                    result=a-b;
                    break;
                case 2:
                    result=a*b;
                    break;
                case 3:
                    while (true) {
                    if (a!=0&&b!=0&&a%b==0) {
                        result=a/b;
                        break;
                    }   else {
                         a = random.nextInt(max+1);
                         b = random.nextInt(max+1);
                    }         
                    }             
                    break;
     
                default:
                    break;
                }
                System.out.println("" + a + f[c] + b + "="  );
               
               
             
            }
          
        }
     
    }

  • 相关阅读:
    eclipse提速01
    eclipse提速02
    快速清空Access资料库中所有表的数据
    删除数据之后自增长列重新开始计数
    JS中控制两个小数位
    JS控制table中tr位置互换
    MIME 类型列表
    JS中对于email格式的判断
    获取网站根目录的方法
    通过存储过程创建SQL作业
  • 原文地址:https://www.cnblogs.com/qjdashuaibi/p/6528383.html
Copyright © 2011-2022 走看看