Print Constant Value
This program prints the value of a constant using the final keyword.
Problem Statement
Write a Java program that declares a constant and prints its value.
Source Code
| 1 | public class PrintConstant { |
| 2 | public static void main(String[] args) { |
| 3 | final double PI = 3.14159; |
| 4 | System.out.println("Constant PI = " + PI + " - Eduinq"); |
| 5 | } |
| 6 | } |
Program Output
Constant PI = 3.14159 - Eduinq
Explanation
A constant PI is declared using the final keyword, meaning its value cannot change once assigned. It is printed with descriptive text, showing how to declare and print constants using final.