Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

char declaration problem

 
Jayant Raj
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Please explain the output to me..

=====================================
char c ='\71';
System.out.println("c is :: " + c);

ANSWER : 9
=====================================

How is this char declaration evaluated?
 
Arvind Giri
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its \uuu where u is an octal value.
hence \71 = 57 = '9'
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'\71' is a bad way to write it. It would be better written as '\071', then it is clearly octal because of the leading zero. On the other hand '\111' is also using octal digits and is legal.
[ August 19, 2005: Message edited by: Barry Gaunt ]
 
nagaraj raja
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai ArvindGiri,

 
nagaraj raja
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai ArvindGiri,

Here i didn't understand how 57 will convert into '9' plz explain
 
Jay Pawar
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello nagaraj raja
ASCII value 57 corresponds to character 9. For more details check the decimal value 57 in this ASCII chart here
Hope that helps
 
Jayant Raj
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it required for us to remember all these ASCII values, for SCJP?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic