013-002-006
Standard Library: Using Math Class
Easy
Problem Description
Standard Library: Using Math Class
In this problem, you will create a program that reads a radius, base, and exponent from standard input, calculates the area of a circle using Math.PI and a power using Math.pow(), then displays each result formatted to 2 decimal places to standard output.
Learning Objective: Learn to combine Java's Math class with Scanner to perform mathematical calculations efficiently
Overview
Read values from standard input and use static methods of the Math class to calculate circle area and powers. Use Math.PI, Math.pow(), and Scanner.
Input Format
radius
base exponent
- Line 1: radius (integer)
- Line 2: base and exponent (space-separated integers)
Specifications
- Calculate area of circle from radius (use Math.PI for pi)
- Calculate power from base and exponent (use Math.pow())
- Output results with 2 decimal places
Input/Output Example
Input:
5
2 3
Output:
Circle area: 78.54
2 to the power of 3: 8.00
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