Why is this array equal to 2d array boolean true?

Hi, I came across the code that my friend sent me, and it’s hard for me to solve the second part of the print instruction. a[3]is 4, which is in line 0 of the column 2 ( b[0][2]), but for some reason a[2], which is equal to 53, which is true for b[2][1] == 43??? (The code prints "true true".)

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]));
  }
}
+3
source share
4 answers

This is because 053- is an octal number equal 43in decimal form.

The prefix 0denotes the octal value in Java and some other languages ​​(Perl, Ruby, C and derived, Javascript, to name a few).

+12
source

, 0, Java.

43 053 .

+3

Java , 0, (base 8) . 053 - , 43 base 10.

JLS

ASCII 0, ASCII 0 7, , , .

+3

Java 0. , 53 43.

+1

All Articles