008-004-012

Defining and Calling Multi-Parameter Methods

Easy

Problem Description

Defining and Calling Multi-Parameter Methods

In this problem: You will define methods with 2-3 parameters (add(int, int), formatName(String, String), calculateBMI(double, double)), call them from main, and display results to standard output.

Learning Objective: Understand how to define and call methods with multiple parameters and learn to work with different data types as arguments

Overview

Methods can accept multiple parameters. By correctly specifying the types and order of arguments, you can perform various operations.

Specifications

  1. add(int a, int b) : Returns the sum of two integers
  2. formatName(String first, String last) : Returns a string in [last], [first] format
  3. calculateBMI(double height, double weight) : Calculates BMI = weight / (height * height) and returns the integer part
  4. Call each method from main and output results

Output Format

Sum: 15
Name: Tanaka, Taro
BMI: 24

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