-
Error Message
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
-
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|