008-001-014

Defining and Calling Methods

Easy

Problem Description

Defining Methods with Return Values

In this problem, you will create a program that reads two integers from standard input, defines an add(int a, int b) method, and prints their sum.

Learning Objective: Understand how to define Java methods and the basics of parameters and return values

Overview

Methods are units that group processing. They can receive values through parameters and return results.

Specifications

  • Read integers a and b from standard input, one per line
  • add(int a, int b) method: receives two integers and returns their sum
  • Print the sum on one line

Examples

  • Input: 3 and 5 → Output: 8
  • Input: 10 and 20 → Output: 30

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