008-002-011

Return Type Method: Area Calculation

Medium

Problem Description

Return Type Method: Area Calculation

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

Overview

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

Specifications

Rectangle Class

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

Main Class

  • Create Rectangle instance (width=5, height=10)
  • Call calculateArea() method and assign result to variable
  • Output in format "Area: [area]"

Output Format

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?