【编程题】(满分23分)
源程序中只能出现JDK1.5中允许的语法或调用。不能使用1.6或更高版本。
import java.text.DecimalFormat; import java.util.Random; public class FourText { public static void main(String[] args) { Random r = new Random(); int usersum = 1; int n, r1, r2, r3; int i = 0; while (i <= 500000) { n = r.nextInt(6) + 1; r1 = r.nextInt(6) + 1; r2 = r.nextInt(6) + 1; r3 = r.nextInt(6) + 1; if (n == r1 || n == r2 || n == r3) { if (n == r1 && n == r2 || n == r1 && n == r3 || n == r2 && n == r3) { if (n == r1 && n == r2 && n == r3) { usersum += 6; } else { if (n * r1 == r2 * r3 || n * r2 == r1 * r3 || n * r3 == r1 * r2) { } else { usersum += 2; } } } else { if (n * r1 == r2 * r3 || n * r2 == r1 * r3 || n * r3 == r1 * r2) { } else { usersum += 1; } } } else { if (n * r1 == r2 * r3 || n * r2 == r1 * r3 || n * r3 == r1 * r2) { } else { usersum -= 1; } } i++; //System.out.println(n+"--"+r1+"--"+r2+"--"+r3+"--"+usersum); } double mmd = (double)Math.abs(usersum)/500000; DecimalFormat df = new DecimalFormat("#0.000"); System.out.println(df.format(mmd)); } }
0.096
0.095
0.099
等等~~这个不一定对,请大家指正。