forked from ehfmakan123/java_algo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDice_Test.java
More file actions
44 lines (38 loc) · 847 Bytes
/
Dice_Test.java
File metadata and controls
44 lines (38 loc) · 847 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package Test;
import java.util.Arrays;
public class DiceTest {
public static int[] arr = new int[] {1,2,3,4,5,6};
public static int N = 3;
public static int[] num = new int[3];
public static int count = 0 ;
public static boolean[] chk = new boolean[100];
public static void dice(int cnt){
if(cnt == N) {
System.out.println(Arrays.toString(num));
count++;
return;
}
for(int i = 0 ; i < arr.length; i++) {
num[cnt] = arr[i];
dice(cnt+1);
}
}
public static void dice2(int cnt){
if(cnt == N) {
System.out.println(Arrays.toString(num));
count++;
return;
}
for(int i = 0 ; i < arr.length; i++) {
if(chk[i] == true) continue;
num[cnt] = arr[i];
chk[i] = true;
dice2(cnt+1);
chk[i] = false;
}
}
public static void main(String[] args) {
dice2(0);
System.out.println(count);
}
}