update
This commit is contained in:
30
DEV.2.1/TP/TP1-introduction/Arguments.java
Normal file
30
DEV.2.1/TP/TP1-introduction/Arguments.java
Normal 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
|
||||
*/
|
BIN
DEV.2.1/TP/TP1-introduction/Grille.class
Normal file
BIN
DEV.2.1/TP/TP1-introduction/Grille.class
Normal file
Binary file not shown.
31
DEV.2.1/TP/TP1-introduction/Grille.java
Normal file
31
DEV.2.1/TP/TP1-introduction/Grille.java
Normal 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("+");
|
||||
}
|
||||
}
|
||||
}
|
7
DEV.2.1/TP/TP1-introduction/Somme.java
Normal file
7
DEV.2.1/TP/TP1-introduction/Somme.java
Normal 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);
|
||||
}
|
||||
}
|
BIN
DEV.2.1/TP/TP1-introduction/Tri.class
Normal file
BIN
DEV.2.1/TP/TP1-introduction/Tri.class
Normal file
Binary file not shown.
20
DEV.2.1/TP/TP1-introduction/Tri.java
Normal file
20
DEV.2.1/TP/TP1-introduction/Tri.java
Normal 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));
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user