This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Explaint the ouput...

 
Tarun Kumar
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
winay Kumar
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Winay.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic