I have just started with Java and I wrote a very simple program of asking
the user to input a value of a variable
and then displaying it.
The program adds a value of 48 to the varaible and displays it. If anyone
knows why this is happening please
let me know. I have initialized the variable to zero and it still doesnt
work.

Anu

03-24-2000, 12:19 PM

Paul Clapham

Re: Error Message

anu <arunaa@rocketmail.com> wrote in message
news:38da866d$1@news.devx.com...
>
> Hi!
>
> I have just started with Java and I wrote a very simple program of asking
> the user to input a value of a variable
> and then displaying it.
> The program adds a value of 48 to the varaible and displays it. If anyone
> knows why this is happening please
> let me know. I have initialized the variable to zero and it still doesnt
> work.
>
> Anu

Did you do something like
char x = (get char from input here);
int i = x;
?
If you did, then you are getting the Unicode value of the character input
(for example, the Unicode value of '1' is 49). Try int i =
Integer.parseInt(x);.

P.S. It would be helpful if you posted the code that's causing your problem.