📚 Cheatsheet

Une collection organisée de snippets de code pour accélérer votre développement. Parcourez, recherchez et copiez en un clic.

Snippets 8

Retour
Boucle for
Facile
for (int i = 0; i < 5; i++) {
    System.out.println("Itération: " + i);
}
Boucle for-each (enhanced for)
Facile
String[] fruits = {"Pomme", "Banane", "Orange"};
for (String fruit : fruits) {
    System.out.println(fruit);
}
Boucle while
Facile
int count = 0;
while (count < 3) {
    System.out.println("Compteur: " + count);
    count++;
}
Déclaration d'une constante
Facile
final double GRAVITY = 9.81;
Déclaration de variables
Facile
int age = 30;
String nom = "Alice";
double pi = 3.14159;
boolean isJavaFun = true;
Instruction switch
Facile
int jour = 4;
switch (jour) {
  case 6:
    System.out.println("Samedi");
    break;
  case 7:
    System.out.println("Dimanche");
    break;
  default:
    System.out.println("Jour de semaine");
}
Programme Hello World
Facile
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}
Structure conditionnelle if-else
Facile
int score = 85;
if (score >= 90) {
    System.out.println("Excellent");
} else if (score >= 50) {
    System.out.println("Passable");
} else {
    System.out.println("Échec");
}