Long Division in Java not working as expected
class LongDiv{ public static void main(String [] args){ final long x = 24*60*60*1000*1000; final long y = 24*60*60*1000; System.out.println(x/y); } } although the expected answer is 1000, but the javac gives it as 5. Reason? The long x you are creating isn't the value you expected. It is in the integer range. To create longs, use: final long x = 24L*60L*60L*1000L*1000L; final long y = 24L*60L*60L*1000L; System.out.println(x/y); The x you computed, in the integer range, was 500654080 . This divided by the y ( = 86400000 ), results in 5.794607407407407... . Java truncates the decimal part which