[aide ]problem java !
Résolu/Fermé
A voir également:
- [aide ]problem java !
- Waptrick java football - Télécharger - Jeux vidéo
- Java apk - Télécharger - Langages
- Jeux java itel football - Télécharger - Jeux vidéo
- Java jre - Télécharger - Langages
- Jeux java itel 5360 ✓ - Forum Mobile
1 réponse
varfendell
Messages postés
3256
Date d'inscription
jeudi 27 décembre 2007
Statut
Membre
Dernière intervention
8 février 2020
699
15 mai 2010 à 18:46
15 mai 2010 à 18:46
Salut,
tu as oublié de sauver ton tableau a chaque fois...il te faut creer un tableau temporaire pour sauvergarder le tableau avec les données actuelle sinon tu ré-ecrit apr dessus.
Voici une solution:
et le résultat donne:
tu as oublié de sauver ton tableau a chaque fois...il te faut creer un tableau temporaire pour sauvergarder le tableau avec les données actuelle sinon tu ré-ecrit apr dessus.
Voici une solution:
public class Tableau { static int[] tableau; static int position = 0; public static void main(String[] args) { tableau = new int[position+1]; ajouter(18); ajouter(2); ajouter (9); ajouter(10); ajouter(113) ; afficher() ; } public static void ajouter (int elem) { int[] temp; temp = new int[position+1]; //tu sauves ton tableau actuel for (int i = 0; i < position; i++) { temp[i] = tableau[i]; } tableau = new int[position+1]; for (int i = 0; i <= position; i++) { tableau[i] = temp[i]; } tableau[position] = elem; position++; } static void afficher() { for (int i = 0; i < position; i++) { System.out.println("position : " + i + " valeur : " + tableau[i]); } } }
et le résultat donne:
position : 0 valeur : 18 position : 1 valeur : 2 position : 2 valeur : 9 position : 3 valeur : 10 position : 4 valeur : 113
16 mai 2010 à 01:05