Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Printing a character

 
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
Marshal
Posts: 52664
121
  • 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: 12343
39
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!!!
 
Don't mess with me you fool! I'm cooking with gas! Here, read this tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!