salut
est ce qu'il ya une méthode pour convertir un tableau de type int en string .
sinon proposer moi une solution.
merci d'avance
salut
est ce qu'il ya une méthode pour convertir un tableau de type int en string .
sinon proposer moi une solution.
merci d'avance
Non ça n'existe pas, mais c'est très simple.
Voila, je te laisse trouver la déclaration des tableaux.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 for(int i=0 ; i<tabInt.length ; i++) { tabString[i] = Integer.toString(tabInt[i]); }
salut
NON c'est pas ça . le tableau tout entier condidéré comme string
par exemple {0,0,1,0,1} ca sera 00101
ben au lieu de mettre les éléments dans un tableau tu les mets dans un StringBuilder et ça marche
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 StringBuilder s = new StringBuilder(); int[] tab = {1,0,0,1,1} for (int i : tab) { s.append(i); } String tabString = s.toString();
salut
j'ai testé la fonction mais il ne considére pas le résultat comme string
il me retourne un message d'erreur quand j'ai essaillé de stocker le résultat dans un tableau de string voici la fonction
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 public static void main(String[] args) { int n=Integer.parseInt(args[0]); String[] t=new String[n]; StringBuilder s = new StringBuilder(); int[] tab = {1,0,0,1,1}; for(int i : tab) { s.append(i); } String tabString = s.toString(); for(int z = 0; z < n; z++) { t[z]=tab; }
Normal tab est un tableau d'entier , tu peux pas le caster en une chaine de caractère ...
tab[z]=s.toString() ; de toute manière le bout de code a aucun sens
Partager