随机生成的300道四则运算
1 import java.util.Random; 2 3 public class Gao { 4 5 public static void main(String[] args) { 6 // TODO Auto-generated method stub 7 8 char f[] = {'+','-','*','/'}; 9 int max =100; 10 for(int i=0;i<300;i++){ 11 Random random= new Random(); 12 int a = random.nextInt(max+1); 13 int b = random.nextInt(max+1); 14 int c = random.nextInt(4); 15 int result = -1; 16 switch (c){ 17 case 0: 18 result = a+b; 19 break; 20 case 1: 21 result = a-b; 22 break; 23 case 2: 24 result = a*b; 25 break; 26 case 3: 27 while (true){ 28 if (a!=0&&b!=0&&a%b==0){ 29 result = a/b; 30 break; 31 }else{ 32 a = random.nextInt(max+1); 33 b = random.nextInt(max+1); 34 } 35 } 36 break; 37 default: 38 break; 39 } 40 System.out.println(""+a+f[c]+b+"="); 41 } 42 } 43 44 }