008-002-011

Return Type Method: Area Calculation

Medium

Problem Description

Return Type Method: Area Calculation

In this problem, you will define a calculateArea(int width, int height) method in a Rectangle class that calculates and returns the area as the product of the given width and height.

Learning Objective: Understand how to define methods with parameters and return values, and how to return calculation results

Overview

Create a method that calculates the area of a rectangle. Methods with return types accept arguments and return calculation results that can be used by the caller.

Input

width
height
  • Line 1: width (integer)
  • Line 2: height (integer)

Output

Area: <area>

Specifications

Rectangle class

  • Method: int calculateArea(int width, int height) - Return area (width × height)

Main Class (provided)

  • public static int calculateArea(int width, int height) - Static wrapper that calls Rectangle's method
  • main() - Reads width and height via Scanner, then prints the area

Example Run

Input:
5
10

Output:
Area: 50

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