This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why the output of x is so strange?

 
jimmy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


( tags added and corrections made to variable names)
[ November 28, 2004: Message edited by: Barry Gaunt ]
 
jimmy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
jimmy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh, I see, thanks alot
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic