首页 > 代码库 > 四则运算

四则运算

public class Operation{
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;
}


}

四则运算