j'ai fait un progr qui charge un tableau jusqu'à la valeur de 100
puis qui affiche le resultat
jentre 1 pui 2 puis 3 puis 100 je sors de la boucle mais le contenu du tableau est 1 2 3 100 1 2 3 100.0 0 0 0 0 0 0(deux fois 1 2 3 100) pourquoi
merci
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 public class moyennetab { public static void charger (double [] t) { double rep=20; int indice=0; while (rep!=100) { rep=Terminal.lireDouble(); t[indice]=rep; indice++; } for (int i=indice;i<=19;i++) { t[i]=0; } } public static void afficher(double [] t) { for (int i=0;i<=19;i++) Terminal.ecrireDoubleln(t[i]); } public static void main(String[] args) { double [] tab=new double[20]; charger (tab); afficher (tab); System.out.println("Hello World!"); } }
Partager