-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConditions.java
More file actions
71 lines (57 loc) · 1.84 KB
/
Copy pathConditions.java
File metadata and controls
71 lines (57 loc) · 1.84 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package demos;
public class Conditions {
public static void main(String[] args) {
double note = 12.5;
// Si
// Oneline :
if (note < 20) System.out.println("Note valide");
// Plusieurs instructions :
if (note > 0) {
System.out.println("La note est valide");
System.out.println("On peut écrire plusieurs instructions");
}
// Si-sinon
if (note < 10) {
System.out.println("Vous n'avez pas la moyenne");
} else {
System.out.println("Vous avez la moyenne !");
}
// Enchaînements :
if (note >= 16) {
System.out.println("Très bien");
} else if (note >= 14) {
System.out.println("Bien");
} else if (note >= 12) {
System.out.println("Bien");
} else {
System.out.println("Bof...");
}
System.out.println();
// Switch case
System.out.println("1- Dire bonjour");
System.out.println("2- Dire au revoir");
System.out.println("3- Dire bonne nuit");
int choix = 2;
// Syntaxe de base
switch (choix) {
case 1:
System.out.println("Bonjour !");
break;
case 2:
System.out.println("Au revoir !");
break;
case 3:
System.out.println("Bonne nuit...");
default:
System.out.println("Mauvais choix...");
break;
}
// Syntaxe oneline (plus récente)
switch (choix) {
case 1 -> System.out.println("Bonjour !");
case 2 -> System.out.println("Au revoir !");
case 3 -> System.out.println("Bonne nuit...");
default -> System.out.println("Mauvais choix...");
}
}
}