四则运算

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; } } }
}

posted on 2017-03-08 10:22  请叫我少爷  阅读(78)  评论(0编辑  收藏  举报

导航