Java - Convertir chiffre en char
Lilou
-
nader -
nader -
Bonjour,
Est ce que quelqu'un sait comment un chiffre en char ou en chaine en Java
En fait je fais une soustraction entre deux char, et ce que je récupère est un int.
Moi je voudrai retrouver la valeur du char correspondant.
Merci
Lilou
Est ce que quelqu'un sait comment un chiffre en char ou en chaine en Java
En fait je fais une soustraction entre deux char, et ce que je récupère est un int.
Moi je voudrai retrouver la valeur du char correspondant.
Merci
Lilou
5 réponses
-
Salut
le plus simple est d'utiliser la méthode statique de "String", valueOf(int i), celle ci te renvoie la valeur en String de l'argument.
Cette méthode fonctionne également avec d'autres types
static String valueOf(boolean b) Returns the string representation of the boolean argument. static String valueOf(char c) Returns the string representation of the char argument. static String valueOf(char[] data) Returns the string representation of the char array argument. static String valueOf(char[] data, int offset, int count) Returns the string representation of a specific subarray of the char array argument. static String valueOf(double d) Returns the string representation of the double argument. static String valueOf(float f) Returns the string representation of the float argument. static String valueOf(int i) Returns the string representation of the int argument. static String valueOf(long l) Returns the string representation of the long argument. static String valueOf(Object obj) Returns the string representation of the Object argument.
-
merci de ta réponse
j'avais déjà essayé mais ca ne marche pas . en fait c peut etre mes chiffres de départ qui ne sont pas bons.
En fait je fais :
char m = 'm' ;
char a = 'a' ;
int i = m ^ a ;
puis
int res = m ^i ;
et a partir de la je voudrai retrouver a ;
est ce possible ?
peut on faire un ou exclusiif entre int et char ?- je vais décomposer l'histoire
char m = 'm'; char a = 'a'; String stringM = String.valueOf(m); String stringA= String.valueOf(a); Integer integerM = Integer.getInteger(stringM); Integer integerA = Integer.getInteger(stringA); int intM = integerM.intValue(); int inta = integerA.intValue(); int i = intM ^ intA ; int res =intM ^i ;
c'est exactement la même chose mais décomposé phase par phase
-
-
Salut, j'ai pas trés bien compri ce que tu voulais faire, mais en règle générale, pour convertir un int en string, ya la méthode toString(),
int c = 2;
string chaine = c.toString();
Ce code met "2" dans la variable chaine.
Maintenant, si tu fais une différence entre 2char, je ne sais plus quelle méthode permet de récupérer le code ascii correspondant. -
-
à vot'service ...
-
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question -
le char peut etre un int ou un string mais pas l'inverse si on pense ou String;
exemple;
char a='A';
int c=a+1; //c=65 car dans cette cas le a=64, 'A'=64,'B'=65,..;
donc si on fait
char x=c;// donc x est le caractère 'B'
enfin pour convertir le int ou le char en String tu peut faire le casting exemple;
String x=""+c/.........