bonjour,
j'ai chargé un tableau avec un string
je souhaite inverser le tableau mais j'ai une erreur d'index

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
 
public class string4 {
 
    public static void main(String[] args) {
 
    	String st="bonjour";
    	char tab[]=new char[10];
    	tab=st.toCharArray();
    	System.out.println(tab);
    	char rev[]=new char[10];
    	int k=9;
    	for (int i=0;i<10;i++)
    	{
    		rev[k]=tab[i];
    		k--;
    	}
    	System.out.println(rev);
 
    }
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7
    at string4.main(string4.java:22)
merci