Forums Register Login

why the output of x is so strange?

+Pie Number of slices to send: Send


( tags added and corrections made to variable names)
[ November 28, 2004: Message edited by: Barry Gaunt ]
+Pie Number of slices to send: Send
sorry,
should be :
System.out.println(" x= " + x + " prefix value=" + resultPre);
System.out.println(" x= " + x + " postfix value=" + resultPost);

and the outprint is :
x=--diamand sign-- prefix value = 5
x=--diamand sign-- postfix value = 4
+Pie Number of slices to send: Send
That's because variable x is declared as a char. So it tries to print out a representation of whatever unicode character has the value 4 (\u0004).

To get it to print "4" you can cast it to an int as in:

+Pie Number of slices to send: Send
oh, I see, thanks alot
I like tacos! And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 402 times.
Similar Threads
passing reference problem.......I think :confused:
Calling a method
Any one solve it?
static block
to ensure immutability
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:27:37.