How to Declare an Octal literal in Java ?


This content was proof-read by Grammarly. You can Try Grammary for FREE

Problem Statement

You want to declare an octal literal in Java.

Solution

Prefix the value with 0. A literal that contains leading zero is an octal number.

public class Main {

    public static void main(String[] args) {
        int octalac1 = 010;
        int octalac2 = 025;
        System.out.println(octalac1);
        System.out.println(octalac2);


    }
}

The output of the above program will be

8

21

Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

%d bloggers like this: