Sunday, August 2, 2009

How can you parse a char to int in java?

I need to convert a char in java to an int... how can this be done?

How can you parse a char to int in java?
Let us start with the parse bit first


http://java.sun.com/javase/6/docs/api/ja...





So you require a string. How do you convert a char to string?


Well take a look at the Character class and you will find this.


http://java.sun.com/javase/6/docs/api/ja...





So to convert a char to a string you use


Character.toString(charData)





Now put that with the parse and you are done.
Reply:i think the easiest way is this:





char c = '9'


int i = Character.getNumericValue(c)





// prints out 9


System.out.println(i);
Reply:Assume that you have a character variable call "c", you can use the command:


int number = Character.digit(c,10);


DONE!


No comments:

Post a Comment