File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes char variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "char variable" Watch "char variable" New topic
Author

char variable

hari harann
Ranch Hand

Joined: Aug 07, 2008
Posts: 54
char c=9;
System.out.println(c);

The above code is compiling fine, but does not produce the output???please explain
Paul Somnath
Ranch Hand

Joined: May 19, 2008
Posts: 177
Originally posted by hari harann:
char c=9;
System.out.println(c);

The above code is compiling fine, but does not produce the output???please explain


Perhaps you meant this:



the primitive literal character is assigned to char variable with single quotes..


Preparing for SCJP 6.0
hari harann
Ranch Hand

Joined: Aug 07, 2008
Posts: 54
no i did not, its this way only
char c=9; without quotes.
if this could compile and even run without exceptions, why not it prints the value???
Paul Somnath
Ranch Hand

Joined: May 19, 2008
Posts: 177
Originally posted by hari harann:
no i did not, its this way only
char c=9; without quotes.
if this could compile and even run without exceptions, why not it prints the value???


If you see the ascii chart(http://www.cppreference.com/ascii.html), then you can see that an integer 9 stands for horizontal tab..
And this is what gets printed on the screen - a horizontal tab.. and you cant see it..
Okay try this:


What do you think this would print??

Try with other ascii values and see what is the output..
[ August 16, 2008: Message edited by: Somnath Paul ]
hari harann
Ranch Hand

Joined: Aug 07, 2008
Posts: 54
Thanks somnath..
Abhishek Kejriwal
Greenhorn

Joined: Aug 07, 2008
Posts: 15
Originally posted by hari harann:
char c=9;
System.out.println(c);

The above code is compiling fine, but does not produce the output???please explain


It is the ASCII value that is printed.
You have to check the ASCII value of 9.


SCJP 6.0
Arijit Daripa
Ranch Hand

Joined: Aug 09, 2008
Posts: 142
Originally posted by Abhishek Kejriwal:


It is the ASCII value that is printed.
You have to check the ASCII value of 9.


The ASCII(or Unicode?) value of 9 is horizontal tab(\t in JAVA).

[ August 16, 2008: Message edited by: ARIJIT DARIPA ]

SCJP 5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: char variable