Extract the output !

Output Question


System.out.println(0123)  

what is the output of given code 

class MyTest
{
public static void main(String args[])
{
int i= 0123
int j= 012
System.out.println(i) // it will print 83 but why?
System.out.println(j) // it will print 10
}
}


4 comments:

  1. Replies
    1. in java, integer with leading 0 is consider as octal, here 0123 is representing octal 123,
      and the output 83 is the decimal conversion of octal's 123.
      for more explanation click on below link

      https://www.javaoneworld.com/2020/05/why-output-of-012-is-10-and-0123-is-83.html

      Delete
    2. Good to know

      Delete
    3. leading 0 will treated as octal

      Delete