zoukankan      html  css  js  c++  java
  • 小学300道四则运算

    主要思路:设想题目形如 a ? b = ,取随机数a、随机数b和随机运算符,循环300次输出 a ? b =,在控制台打印出300道题目。

    package task;
    
    import java.util.Arrays;
    import java.util.List;
    
    public class Task2 {
    public static void main(String urgs[]){
            //定义a、b数组并分配300个空间
            int [] a=new int[300];
            int [] b=new int[300];
            List list1 =Arrays.asList(b);
            
            //定义z数组存放运算符,定义c数组并分配300个空间
            String[] z ={"+","-","*","/"};
            String [] c =new String[300];
            List list =Arrays.asList(c);
            
            //取随机数,循环300次,输出a数组中的数加C数组中的运算符和b数组中的数
            for(int i=0;i<300;i++){
                 a[i]=(int)(Math.random()*100);
                 b[i]=(int)(Math.random()*100);
                 c[i] =z[(int)(Math.random()*4)];
                 if(list.contains("/")&&list1.contains(0)){ 
                     b[i]=(int)(Math.random()*100+1); 
                 }
                System.out.println(a[i]+c[i]+b[i]+"=");
            }
            
        }
    
    }

     

  • 相关阅读:
    线程3 线程池和文件下载服务器
    线程 2
    线程 1
    线程间操作
    编写高质量的代码-------从命名开始
    基于.NET平台常用的框架整理
    消息队列
    我是一个线程
    linux 网络命令
    css hack比较全 --- 转
  • 原文地址:https://www.cnblogs.com/krylova/p/6526707.html
Copyright © 2011-2022 走看看