Skip to main content

Question about weird output

1 reply [Last post]
drtopper
Offline
Joined: 2006-05-28
Points: 0

I'm not sure how this came about, but when I compile and run this code it displays a completely different number and I was just wondering if anyone knows why. With the 0 in front of it, it displays 422, but without, it's 646. For 072 it displays 58, but without it's still 72. From 00 to 07 it displays the integer without the 0 in front and on 08 and 09 it won't compile because it says the integer is too large. everything else starting at 10 and above that I've tried compiles but displays a different number. Anyone have an explanation?

public class Test {
public static void main( String[] args ) {
System.out.println(0646);
}
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
briand
Offline
Joined: 2005-07-11
Points: 0

Your question is not really performance related, so it should really be targeted at a different forum. Regardless, the leading 0 is telling the compiler that the number is expressed in octal instead of decimal. Try using a calculator that supports binary, octal, hex and decimal and enter the values you've been experimenting with. Things will then become quite obvious.

Brian