//利用随机数来搞事//虽然写的不好,但意思是差不多的public class Test{ public static void main(String[] args){ int m = (int)(Math.random()*100); //随机数1,范围(0到99); int n = (int)(Math.random()*100); //随机数2,范围(0到99); int c = (int)(Math.random()*4); //随机数3, 范围(0到3),用于随机产生加减乘除 int num = 0; switch(c){ case 0: num = m + n; System.out.println(m+" + "+n+" = ?"); break; case 1: num = m - n; System.out.println(m+" - "+n+" = ?"); break; case 2: num = m * n; System.out.println(m+" * "+n+" = ?"); break; case 3: num = m / n; System.out.println(m+" / "+n+" = ?"); break; } System.out.println("正确答案是:" + num); }}