• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

'0' and 0

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
char c='0';
char i=0;
System.out.println(Integer.toHexString(c));//30
System.out.println(Integer.toHexString(i));//0
if (c!=i)
System.out.println(c+" is not equal to "+i);
// 0 is not equal to 0
why is that here in a regular System.out.println statement the output doesn't differentiate between two different values (0x30 and 0x00)?
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jennifer,
You might have a bug in your runnable code. The example that you typed in above works correctly. The last println prints out:
0 is not equal to
with the last value being a space (0 = space character).
The following will show you it easier.

Regards,
Manfred.
 
Jennifer Wallace
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
U are right! Output's just fine! Thanks!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!