2019年9月16日课堂随机出题
(1)源代码
import java.util.*; public class FourFundamental { public static void main(String[] args) { int i; Random R = new Random(); for(i=0;i<30;i++) { switch(R.nextInt(4)+1) { case 1: jia(); break; case 2: jian(); break; case 3: cheng(); break; case 4: chu(); break; } } } public static void jia() { Random T = new Random(); Random R = new Random(); System.out.println(T.nextInt(101)+" + "+R.nextInt(101)+" = "); } public static void jian() { Random T = new Random(); Random R = new Random(); System.out.println(T.nextInt(101)+" - "+R.nextInt(101)+" = "); } public static void cheng() { Random T = new Random(); Random R = new Random(); System.out.println(T.nextInt(101)+" * "+R.nextInt(101)+" = "); } public static void chu() { Random T = new Random(); Random R = new Random(); System.out.println(T.nextInt(101)+" / "+R.nextInt(101)+" = "); } }
(2)输出结果