This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

char variable

 
hari harann
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 177
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
hari harann
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 177
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks somnath..
 
Abhishek Kejriwal
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Arijit Daripa
Ranch Hand
Posts: 142
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic