salut,et bonne année à tout le monde.Bon j'ai fait un programme qui modifie les elements d'un tableau saisis au debut
mais le probléme c'est lors de l'affichage des premiers elements saisis"procédure affichage0" il me donne les nouvelles valeurs des elements du tableau,enfin de compte je veux afficher les 2 :
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 import java.util.Scanner; public class Modification1 { public static void initialisation(int []t){ Scanner lire= new Scanner(System.in); int i; for( i=0;i<t.length;i++){ System.out.println("saisir le "+i+" element"); t[i]=lire.nextInt(); } } public static void affichage0(int []t){ for( int i=0;i<t.length;i++){ System.out.print("/"+t[i]); }} public static void test(int []t){ Scanner lire= new Scanner(System.in); String reponse=""; while(!reponse.equals("non")){ System.out.println("saisir l'indice de la position :"); int p=lire.nextInt(); System.out.println("voulez vous modifier ces elements ?? tapez OUI pour modification et AUTRES pour sortir"); String rep=lire.next(); if(rep.equals("oui")|| rep.equals("OUI")){ System.out.println("par quel nombre voulez vs le modifié??"); int nombre=lire.nextInt(); t[p]=nombre; System.out.println("voulez-vous modifier un autre element??"); reponse=lire.next(); } else System.exit(0); } } public static void affichage(int []t){ for( int i=0;i<t.length;i++){ System.out.println(t[i]); }} public static void main(String[] args) { Scanner lire= new Scanner(System.in); System.out.println("donner le nombre d'elements du tableau : "); int n=lire.nextInt(); int []tab=new int[n]; initialisation(tab); test(tab); System.out.println("FIRST ELEMENTS:"); affichage0(tab); System.out.println(""); System.out.println("NEW ELEMENTS:"); affichage(tab); }}
FIRST ELEMENTS:....
NEW ELEMENTS:.....
mais pour FIRST elements il me donne les memes que NEW elements
donc voila.VOTRE AIDE SVP.
Partager