-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exercice2.java
33 lines (27 loc) · 906 Bytes
/
Exercice2.java
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
import java.util.Arrays;
import java.util.Random;
public class Exercice2 {
public static void main(String[] args) {
Random random = new Random();
int[] randomArray;
int passes = 0;
do {
passes++;
int a = random.nextInt(0, 1000);
int b = random.nextInt(0, 1000);
int c = random.nextInt(0, 1000);
randomArray = new int[]{a, b, c};
} while (! checkArray(randomArray));
System.out.println("Le tableau retenu est : " + Arrays.toString(randomArray) + ".\nIl a fallu " + passes + " essais pour trouver ce tableau.");
}
static boolean checkArray(int[] intArray) {
if (intArray[0] % 2 == 0) {
if (intArray[1] % 2 == 0) {
if (intArray[2] % 2 != 0) {
return true;
}
}
}
return false;
}
}