• 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

why it doesn't print max value of char

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
if we try to run following lines of code
System.out.print(Byte.MAX_VALUE+",");
System.out.print(Character.MAX_VALUE);
It will print
127,?
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);
output
65534
Please Explain me this

Thank You
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In this case
System.out.print(Character.MAX_VALUE);
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.
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Valadimir & david.
I got it.
 
reply
    Bookmark Topic Watch Topic
  • New Topic