首页 > 代码库 > 四则运算

四则运算

public class sizeyunsuan {     public static void main(String[] args) {                 Random random = new Random();                 for (int j = 1; j <= 300; j++) {                     int algorithm = random.nextInt(4);                     int num1 = random.nextInt(100);                     int num2 = random.nextInt(100);
switch (algorithm) { case 0:
                 System.out.println("第" + j + "个:");
System.out.println(num1 + "*" + num2 + "=" ); break; case 1:
                 System.out.println("第" + j + "个:");
System.out.println(num1 + "+" + num2 + "=" ); break; case 2:
                 System.out.println("第" + j + "个:");
System.out.println(num1 + "-" + num2 + "=" ); break; case 3:
if (num2 == 0) {
j--; break; } else {
                    System.out.println("第" + j + "个:");
System.out.println(num1 + "/" + num2 + "=");
} break; default: break; } } }
}

四则运算