Skip to main content

Character to Int conversions.

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

Hi,
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 in.read() 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.
bune
Offline
Joined: 2006-05-23

1.
[code]
int i = 5;
char c = (Integer.toString(i)).charAt(0);
[/code]

2.
[code]
char c='5';
int i = Integer.parseInt(String.valueOf(c));
[/code]

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