File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes why  it doesn't print  max value of char Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

JavaRanch » Java Forums » Java » Java in General
Bookmark "why  it doesn Watch "why  it doesn New topic

why it doesn't print max value of char

Waez Ali

Joined: Jan 10, 2005
Posts: 22
if we try to run following lines of code
It will print
Question:- Why It Doesn't Print 65535 as it is the MAX value of Charecter ?
However we can print
System.out.print(Character.MAX_VALUE - 1);
Please Explain me this

Thank You
Vladimir Bezugliy
Ranch Hand

Joined: Sep 29, 2004
Posts: 33
In this case
method will be executed.

But in that case
System.out.print(Character.MAX_VALUE - 1);
will be executed method

because result of (Character.MAX_VALUE - 1) will be int type.
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
The reason it does this is that Character.MAX_VALUE is a char, so it gets turned into a single-character String rather than formatted as 65535. Since you don't have a font that supports the 0xFF00 code page (code point?), it uses the "I don't know what this character is" character: "?".

Another way to view this value as a number, rather than applying math to the number, is to cast it to an int directly.
[ January 27, 2005: Message edited by: David Harkness ]
Waez Ali

Joined: Jan 10, 2005
Posts: 22
Thanks Valadimir & david.
I got it.
I agree. Here's the link:
subject: why it doesn't print max value of char