-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiceGame2.java
More file actions
26 lines (24 loc) · 579 Bytes
/
DiceGame2.java
File metadata and controls
26 lines (24 loc) · 579 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.java;
import java.util.Random;
/**
* @Author: mzy
* @Date: 2019-1-22 18:11
*/
public class DiceGame2 {
/**
* @编写程序模拟掷骰子游戏
*/
public static void main(String[] args){
int[] a = new int[11];// 老师说已初始化
Random r=new Random();
for (int i = 1; i <=5000; i++) {
int n1=r.nextInt(6)+1;
int n2=r.nextInt(6)+1;
int z=n1+n2;
a[z-2]++;
}
for (int i = 0; i < a.length; i++) {
System.out.println(i+2+":"+a[i]+"次");
}
}
}