This commit is contained in:
Emmanuel Srivastava
2025-01-27 20:32:32 +01:00
parent d582a5055b
commit 4071ce2277
24 changed files with 568 additions and 4 deletions

View File

@@ -0,0 +1,30 @@
public class Arguments {
public static void main(String[] args) {
if (args.length > 0) {
System.out.println("Bonjour, " + args[0] + " !");
if (args.length > 1) {
System.out.println("Bonjour, " + args[1] + " !");
}
if (args.length > 2) {
System.out.println("Bonjour, " + args[2] + " !");
}
} else {
System.out.println("Aucun nom n'a été fourni !");
}
}
}
/*
public class Arguments {
public static void main (String[] args) {
for (String nom ': args) {
System.out.println("Bonjour, " + nom + " !");
}
}
}
AVEC UNE BOUCLE for
*/

Binary file not shown.

View File

@@ -0,0 +1,31 @@
public class Grille {
public static void main(String[] args) {
// Vérification de la validité de l'argument
if (args.length == 0 || Integer.parseInt(args[0]) <= 0) {
System.out.println("Pas de tableau");
} else {
int taille = Integer.parseInt(args[0]);
// Construction de la grille
for (int i = 0; i < taille; i++) {
// Ligne horizontale
for (int j = 0; j < taille; j++) {
System.out.print("+-");
}
System.out.println("+");
// Ligne verticale
for (int j = 0; j < taille; j++) {
System.out.print("| ");
}
System.out.println("|");
}
// Dernière ligne horizontale
for (int j = 0; j < taille; j++) {
System.out.print("+-");
}
System.out.println("+");
}
}
}

View File

@@ -0,0 +1,7 @@
public class Somme {
public static void main(String[] args) {
int somme = Integer.parseInt(args[0]) + Integer.parseInt(args[1]);
System.out.println("La somme des nombres est : " + somme);
}
}

Binary file not shown.

View File

@@ -0,0 +1,20 @@
import java.util.Arrays;
public class Tri {
public static void main(String[] args) {
if (args.length == 0) {
System.out.println("Veuillez fournir des nombres en arguments.");
return;
}
int[] nombres = new int[args.length];
for(int i = 0; i<args.length; i++) {
nombres[i] = Integer.parseInt(args[i]);
}
Arrays.sort(nombres);
System.out.println("Voici votre liste de nombre trié : "+Arrays.toString(nombres));
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,13 @@
méthode de classe :
Une méthodez de classe est dans une classe
String s = String.valueOf(12);
TABLEAUX
Ex :
int[] tab = null;
tab = new int[500];
tab[3]=12;
int l = tab.length;
double[] mesures = {0.5,-1.4,7.0};
tab = new int[] {1,2,3,12}; //qqc dont on pouvait pas faire en C

Binary file not shown.

Binary file not shown.