File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printing a character

 
Tarun Oohri
Ranch Hand
Posts: 189
  • 0
  • 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
Pie
Posts: 47293
52
  • 0
  • 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
  • 0
  • 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
Pie
Posts: 12022
25
Chrome Java Linux
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks fred for makng it more clear...got it this time ...
Cheers!!!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic