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:
parent
fc0ff94dba
commit
32ec759aa6
2 changed files with 18 additions and 5 deletions
|
@ -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
18
src/exercice2part1.java
Normal 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();
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue