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

  • 相关阅读:
    升级WP应用时注意的问题——WMAppManifest.xml
    MVVM Light (Part 4)
    Windows Phone 7的About模板——Your Last About Dialog(2)支持多语言
    MVVM Light 开始
    在ScheduledTaskAgent中使用HttpWebRequest
    年会抽奖程序 支持单次单个抽奖和单次多个抽奖,自定义抽奖设置
    WIndows Phone 7的MVVM Light框架
    MVVM Light (Part 3)
    MVVM Light 行为
    [转]如何在设计中应用颜色搭配技巧
  • 原文地址:https://www.cnblogs.com/qjdashuaibi/p/6528383.html
Copyright © 2011-2022 走看看