008-004-008

Method Return Value: Square Number

Easy

Problem Description

Method Return Value: Square Number

In this problem, you will create a program that defines a square method in the Calculator class, reads an integer from standard input, calculates its square, and prints the result.

Learning Objective: Understand how to return values from methods

Overview

Create a method that receives an integer, calculates its square, and returns the result.

Input

  • Line 1: integer n

Output

  • Print the square of n

Specifications

  • Define square method in Calculator class
  • Receive int parameter number
  • Calculate square of number and return as int
  • In Main class, use Scanner to read input and print the result of the square method

Usage Example

Input: 5
Output: 25

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