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

  1. Define static int square(int n) method in MathUtil class (returns n squared)
  2. Define static int cube(int n) method (returns n cubed)
  3. Read one integer from Scanner
  4. Print Square: <n^2> and Cube: <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