012-002-008
Calculating with Static Methods
Easy
Problem Description
Calculating with static Methods
In this problem, you will create a program that defines static methods (square and cube) in a MathUtil class, calls them without creating an instance, and displays the square and cube of an integer to standard output.
Learning Objective: Understand how to define and call static methods
Overview
Define static methods in a MathUtil class and call them without creating an instance.
Specifications
- Define
static int square(int n)method inMathUtilclass (returns n squared) - Define
static int cube(int n)method (returns n cubed) - Read one integer from Scanner
- Print
Square: <n^2>andCube: <n^3>
Input Example
3
Output Format
Square: 9
Cube: 27
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