zoukankan      html  css  js  c++  java
  • Java 生成二进制加减法题目

    日常算数,有益身心健康。

            int a;
            int b;
            int result;
            int symbol;
            int count = 50;
            Random random = new Random();
            for(int i = 0; i < count;i++) {
                symbol = Math.abs(random.nextInt()) % 2;
                
                if (symbol == 0){ // 加号
                    a = Math.abs(random.nextInt()) % 100;
                    b = Math.abs(random.nextInt()) % 100;
                    result = a + b;
                    
                    System.out.println((i + 1) + "	" + 
                            Integer.toBinaryString(a) + " + " + 
                            Integer.toBinaryString(b) + " = " + 
                            "		答案:" + a + "+" + b + "=" + result);
                } else { // 减号
                    a = Math.abs(random.nextInt()) % 100;
                    b = Math.abs(random.nextInt()) % a;
                    result = a - b;
                    
                    System.out.println((i + 1) + "	" + 
                            Integer.toBinaryString(a) + " - " + 
                            Integer.toBinaryString(b) + " = " + 
                            "		答案:" + a + "-" + b + "=" + result);
                }
            }        
  • 相关阅读:
    java 基础7
    java 基础5
    java 基础6
    java 基础4
    java 基础2
    java 基础3
    java 基础1
    使用HTML的基本结构创建网页
    jsp Servlet 文件上传
    Filter过滤器 不登陆无法访问其他页面
  • 原文地址:https://www.cnblogs.com/foxlee1024/p/9004363.html
Copyright © 2011-2022 走看看