please explain this code

saragondla

saragondla

@saragondla-lCltzb Oct 24, 2024
public class B {

public int add()
{
return 011;
}
public static void main(String[] args)
{
B b1=new B();

System.out.println(b1.add());
}

}



the output is 9, how it will comes....

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Omesh3

    Omesh3

    @omesh3-FD9oas Nov 25, 2009

    011 is octal for 9. Java interprets numbers starting with "0" as octal numbers (numbers with base 8). Remove the leading zero and you will get a different print out.😁

    0-9 in base 8 (octal):
    0 = 000
    1 = 001
    2 = 002
    3 = 003
    4 = 004
    5 = 005
    6 = 006
    7 = 007
    8 = 010
    9 = 011