✏️ Explanatory Question

Which number is denoted by leading zero in java?

👁 743 Views
📘 Detailed Answer
No previous question
No next question
💡

Answer with Explanation

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

No previous question
No next question