This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes char declaration problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "char declaration problem" Watch "char declaration problem" New topic
Author

char declaration problem

Jayant Raj
Ranch Hand

Joined: Mar 11, 2004
Posts: 42
Hi,

Please explain the output to me..

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

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

How is this char declaration evaluated?


regards,<br />Jayant Raj<br /> <br />SCJP 1.4 [98%]<br />SCWCD 1.4 [91%]<br />SCBCD [In Progress]
Arvind Giri
Ranch Hand

Joined: Jun 26, 2005
Posts: 91
its \uuu where u is an octal value.
hence \71 = 57 = '9'


Regards<br /> <br />Arvind Giri<br />MCA,SCJP 1.4,SCWCD 1.4<br />Looking for SCDJWS
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
'\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 ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
nagaraj raja
Ranch Hand

Joined: Aug 06, 2005
Posts: 36
hai ArvindGiri,

nagaraj raja
Ranch Hand

Joined: Aug 06, 2005
Posts: 36
hai ArvindGiri,

Here i didn't understand how 57 will convert into '9' plz explain
Jay Pawar
Ranch Hand

Joined: Aug 27, 2004
Posts: 411
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


Cheers,<br />Jay<br /> <br />(SCJP 1.4)<br />Heights of great men were not achieved in one day, they were toiling day and night while their companions slept.
Jayant Raj
Ranch Hand

Joined: Mar 11, 2004
Posts: 42
Is it required for us to remember all these ASCII values, for SCJP?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: char declaration problem
 
Similar Threads
why "...." is valid?
How can it be valid?
'\u000' != " " true or false
char default value ?
IS THIS LEGAL