Hi I happen to come across a code that my friend sent me, and am having trouble making out the second part of the print statement.. a[3]
is 4, which is in row 0 column 2 (b[0][2]
), but why is a[2]
which is 53, proving true to b[2][1] == 43
??? (The code prints 'true true' btw.)
class Ex1{
public static void main(String[] args) {
int a[] = { 1,2,053,4};
int b[][] = { {1,2,4} , {2,2,1},{0,43,2}};
System.out.print(a[3]==b[0][2] );
System.out.print(" " + (a[2]==b[2][1]));
}
}
This happens because 053
is an octal number equal to 43
in decimal.
The 0
prefix denotes an octal value in Java and some other languages (Perl, Ruby, C and derived, Javascript to name a few).
Numbers starting with 0
are octal in Java.
And in your case 43
decimal is equal to 053
octal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With