Exercice 2.1: Fonction Avec Template pour AfficheTableau. Utilisation de type Short et Character à la place de 'short' et 'char'

This commit is contained in:
Yohan Boujon 2023-10-15 20:07:03 +02:00
parent fc0ff94dba
commit 32ec759aa6
2 changed files with 18 additions and 5 deletions

View file

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

18
src/exercice2part1.java Normal file
View file

@ -0,0 +1,18 @@
public class exercice2part1 {
public static void main(String[] argv) {
Short[] ConstTab = { 1, 2, 3, 4, 5 };
Character[] MonTableau = new Character[5];
for (int i = 0; i < MonTableau.length; i++) {
MonTableau[i] = (char) ('a' + (char) (i));
}
afficheTableau(ConstTab);
afficheTableau(MonTableau);
}
public static <T> void afficheTableau(T[] array) {
for (T element : array) {
System.out.print(element + " ");
}
System.out.println();
}
}