• 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

Explaint the ouput...

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class T6
{
public static void main(String[] args)
{
long intBig = Integer.MAX_VALUE + 1;
long longBig = Integer.MAX_VALUE + 1L;
if(intBig==longBig){
System.out.println("True");
}else{
System.out.println("False");
}
}
}

It's output is False. how the output is coming.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tarun,

in this first statement "long intBig = Integer.MAX_VALUE + 1;" its directly incrementing Integer max value by 1 which in turn its going to negative value ie Integer.MIN_VALUE and then its assigning to long data type.

where as in second statement "long longBig = Integer.MAX_VALUE + 1L;" first its converting to long, then incrementing by 1 and then assigning.

if you print intBig, longBig its giving -2147483648, 2147483648 respectively.
 
Tarun Kumar
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Winay.
reply
    Bookmark Topic Watch Topic
  • New Topic