Skip to main content

Character to Int conversions.

1 reply [Last post]
Joined: 2006-04-18

I'm trying to complete a program that reads in a file character by character, push's them onto a stack and then pops them off. The resulting file is then reversed. The method that I have to use involves the and out.write methods. These methods return an write the integer equivalent values of the characters therefore,
1 - How do you convert an integer to a character?
2 - How do you convert a character to an integer?
Any help would be great, I cant find anything online or in text-books.
Thanks, Chris.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2006-05-23

int i = 5;
char c = (Integer.toString(i)).charAt(0);

char c='5';
int i = Integer.parseInt(String.valueOf(c));

There might be better ways to do it, but this will work. Also remember to catch exceptions when trying to parse non-numerical Characters.

Message was edited by: bune