Je n'arrive plus à retrouver une méthode pour effacer un int d'un tableau.
Qu'est-ce qui cloche ?
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 public class elimineInt { public static int [] deplaceTab(int [] arrivees, int n){ for(int i=n; i<arrivees.length; i++){ if(arrivees[i]==n){ while (i<arrivees.length-1){ arrivees[i]=arrivees[i+1]; } arrivees[arrivees.length-1]=0; } } return arrivees; } public static void main(String[] args) { // TODO Auto-generated method stub int[]arrivees ={3, 2, 1}; int n=3; arrivees=deplaceTab(arrivees, n); for (int i=0; i<arrivees.length; i++){ System.out.println(arrivees[i]); } } }
Partager