Compare commits

...

2 Commits

Author SHA1 Message Date
Meutel 298af8b3b9 Inversion variables, tableau 2019-05-30 21:38:31 +02:00
Meutel dbd88e5af7 Affichage tableau int 2019-05-30 21:38:03 +02:00
3 changed files with 98 additions and 0 deletions

58
InvTab.java Normal file
View File

@ -0,0 +1,58 @@
import static utils.Utils.*;
public class InvTab {
public static final void main(String[] args) {
afficher("Inversion tableau");
int[] tab = { 34, 568, 11, 678, 0};
afficherTabInt(tab);
int[] tab2 = new int[tab.length];
for(int compteur=0; compteur<tab.length; compteur++){
int element = tab[compteur];
int compteur2 = tab.length-compteur-1;
tab2[compteur2] = element;
}
afficherTabInt(tab2);
}
}

28
InvVars.java Normal file
View File

@ -0,0 +1,28 @@
import static utils.Utils.*;
public class InvVars {
public static final void main(String[] args) {
afficher("Inversion");
int a= 5;
int b= 1;
afficher("a = ",a);
afficher("b = ",b);
int c=a;
a=b;
b=c;
afficher("a = ",a);
afficher("b = ",b);
}
}

View File

@ -18,6 +18,18 @@ public class Utils {
}
System.out.println();
}
public static final void afficherTabInt(int... args) {
if (args == null) {
System.out.println("null");
} else {
String str = Arrays.stream(args)
.boxed()
.map(i -> i+"")
.collect(Collectors.joining(" "));
System.out.println(str);
}
System.out.println();
}
public static int lireEntier() {
try (Scanner reader = new Scanner(System.in)) {