• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Printing a character

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everyone
Can anyone explain why the output is coming out to be blank in the following code.Thanks!!!
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks fred for makng it more clear...got it this time ...
Cheers!!!
 
Why fit in when you were born to stand out? - Seuss. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic