美文网首页
随机生成四则运算

随机生成四则运算

作者: 筱碯 | 来源:发表于2018-03-08 22:11 被阅读0次

    package text1;

    public class P1 {

    public static void gs(Object obj){

    System.out.println(obj);

    }

    public static void main(String[] args){

    int count = 0;

    for(int i=0;i<300;i++){

    int a = (int)(Math.random()*100);

    int b = (int)(Math.random()*100);

    int c = (int)(Math.random()*100);

    int j=1;

    if(0<=c&&c<10)

    j=1;

    else if(10<=c&&c<20)

    j=2;

    else if(20<=c&&c<30)

    j=3;

    else if(30<=c&&c<40)

    j=4;

    else if(40<=c&&c<50)

    j=5;

    else if(50<=c&&c<60)

    j=6;

    else if(60<=c&&c<70)

    j=7;

    else if(70<=c&&c<80)

    j=8;

    else if(80<=c&&c<90)

    j=9;

    else

    j=10;

    switch(j){

    case 1:

    gs(a + "+" + b + "=");

    break;

    case 2:

    gs(a + "-" + b + "=");

    break;

    case 3:

    gs(a + "*" + b + "=");

    break;

    case 4:

    gs(a + "/" + b + "=");

    break;

    }

    count++;

    }

    gs("一共有:"+count+"四则运算题目");

    }

    public static void jf(int a,int b){

    if(a>=b)

    gs(a + "-" + b + "=");

    else{

    gs(b + "-" + a + "=");

    }

    }

    public static void cf(int a,int b){

    if(b>0)

    gs(a + "/" + b + "=");

    else{

    b=b+1;

    gs(a + "/" + b + "=");

    }

    }

    }

    相关文章

      网友评论

          本文标题:随机生成四则运算

          本文链接:https://www.haomeiwen.com/subject/tgdufftx.html