随机生成300道四则运算

public class Demo{
public static void main(String[] args) {
int first ;
int second ;
int third;

for (int i=0;i<300;i++){
first =(int) (Math.random()*100);
second = (int)( Math.random()*100);
third=(int)(Math.random()*4);
switch(third) {
case 0:
System.out.println(first +"+"+second+"=");
break;
case 1:
System.out.println(first+"-"+ second+"=");
break;
case 2:
System.out.println (first +"*"+ second+"=");
break;
case 3:
if(second==0){
second=(int)(Math.random()*100+1);
System.out.println(first+ "/" +second+"=");
}else{
System.out.println(first+ "/" +second+"=");
}
break;
}
}
}
}

 

posted @ 2017-03-09 15:27  hui不去的曾经  阅读(108)  评论(0编辑  收藏  举报