This week's giveaway is in the Threads forum.
We're giving away four copies of Java Concurrency Live Lessons and have Doug Schmidt on-line!
See this thread for details.
Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Printing a character  RSS feed

 
Tarun Oohri
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone
Can anyone explain why the output is coming out to be blank in the following code.Thanks!!!
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The 0x000a char is the linefeed character, so you would expect to get two blank lines before 10 is printed. Your code prints:-


10
and System.out.println(); System.out.println((int)d); prints one blank line:-

10
 
Tarun Oohri
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:The 0x000a char is the linefeed character, so you would expect to get two blank lines before 10 is printed. Your code prints:-


10
and System.out.println(); System.out.println((int)d); prints one blank line:-

10

Thanks Campbell for your reply but i am not able to get you...What is "0x000a" ? From where it came ? Is it a uni code of number 10 ?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12443
42
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
0x000a is the hexadecimal representation of the decimal number 10. It's just a different way to write same number. "ten", "10", X (roman numeral), 1010 (binary), 12 (octal) are all different ways to represent the same concept of ten.

So what do you expect to print out? you defined 'd' to be a char type. that means it represent a character. If you look at the ascii chart, you can see that 10 as a character is a line feed. In the old days, that would advance the paper one line. On a terminal, it moves the cursor down one line.

It IS printing...it is just not printing what you think it should.
 
Tarun Oohri
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks fred for makng it more clear...got it this time ...
Cheers!!!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!