012-001-011
Defining Static Constants
Medium
Problem Description
Defining static Constants
In this problem, you will create a program that defines mathematical constants PI and E as static final fields in a MathConstants class, reads a radius from standard input, computes the area of a circle, and displays the results to standard output.
Learning Objective: Understand how to define constants using static final
Overview
Define constants with static final and create values usable across the class.
Specifications
- Define PI (3.14159) and E (2.71828) in MathConstants class
- Make them immutable with static final
- Read one integer (radius) from standard input
- Output circle area and constant values
Input Format
radius (integer)
Output Format
PI = 3.14159
Circle area (r=<radius>): <area>
E = 2.71828
Example
Input: 5
Output:
PI = 3.14159
Circle area (r=5): 78.53975
E = 2.71828
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up