CrazyEngineers
  • please explain this code

    saragondla

    Member

    Updated: Oct 24, 2024
    Views: 998
    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....
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Omesh3

    MemberNov 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
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register