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

}

 

posted @ 2017-03-09 17:22  三仰化二铁  阅读(178)  评论(0编辑  收藏  举报