For char, the print/println methods translate the character into one or more bytes according to the platform's default character encoding. That is why while printing a char value of 0, a blank space is printed instead of 0 (even though the char's integral value is 0).
Can you please elaborate this. Unable to understand the mystry.
About Question enthuware.ocajp.i.v8.2.2017 :
Moderator: admin
-
- Posts: 8
- Joined: Mon Jul 06, 2020 1:11 pm
- Contact:
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.2017 :
Not really sure which part you don't understand. Like the ascii value of 'a' is 97, so, if you try to print a char variable containing 97, a will be printed. Similarly, whatever character is represented by value 0, that is printed (it is just a blank character).
If you like our products and services, please help us by posting your review here.
-
- Posts: 8
- Joined: Mon Jul 06, 2020 1:11 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.2017 :
So, though 0 don't have any character representation that's why it is printing space. Thanks for the explanation.admin wrote: ↑Sat Aug 01, 2020 11:08 amNot really sure which part you don't understand. Like the ascii value of 'a' is 97, so, if you try to print a char variable containing 97, a will be printed. Similarly, whatever character is represented by value 0, that is printed (it is just a blank character).
-
- Posts: 3
- Joined: Thu Dec 23, 2021 5:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.2017 :
Well, the correct answer for any operating system would be: "none of the above"
(char)0 is ascii NUL. How this is printed depends on the operating system shell.
On Linux it could be (char)32, "0" or even "\bf". So #2 and #3 could be correct answers as well.
E.g.: Emacs prints the NUL as ^@. And the last statement is a print, not a println, so actual the output from an Emacs shell window would be:
0.0 ^@ false------------------------------
(char)0 is ascii NUL. How this is printed depends on the operating system shell.
On Linux it could be (char)32, "0" or even "\bf". So #2 and #3 could be correct answers as well.
E.g.: Emacs prints the NUL as ^@. And the last statement is a print, not a println, so actual the output from an Emacs shell window would be:
0.0 ^@ false------------------------------
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.2017 :
No, what you are taking about is how programming environments use the value 0. For eg. 0 may be used to represent a null reference.
But is not what this question is about. It is very clearly creating a java char variable containing a value zero and how it is printed. The integral value of a char is represented as a character based on the default character encoding of the platform on which the JVM is running. So, the given answer and explanation are correct.
But is not what this question is about. It is very clearly creating a java char variable containing a value zero and how it is printed. The integral value of a char is represented as a character based on the default character encoding of the platform on which the JVM is running. So, the given answer and explanation are correct.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 49 guests