Which number is denoted by leading zero in java?

Short Answer
Views 626

Answer:

In Java, if a numeric literal (integer literal) is prefixed with a leading zero (0), it is treated as an octal (base-8) literal. Octal literals are represented using digits from 0 to 7.

For example:


int octalNumber = 075; // This is an octal literal
System.out.println(octalNumber); // Output: 61 (decimal equivalent of octal 75)

In this example, the number 075 is an octal literal because it starts with a leading zero. The output of the program is the decimal equivalent of the octal number, which is 61. It's important to note that using leading zeros to represent octal literals is a feature of the language syntax in Java.

If you want to represent integers in decimal (base-10) format, simply omit the leading zero. For example:


int decimalNumber = 123; // This is a decimal literal
System.out.println(decimalNumber); // Output: 123

Related Articles:

This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of Java Programming Language, click the links and dive deeper into this subject.

Join Our telegram group to ask Questions

Click below button to join our groups.