Challenge: Create a Method

Methods let you group code into reusable actions.

In this challenge, you’ll create two methods and call them from main.

Your tasks

  1. Create a method named sayHiTo that:

    1. Takes one parameter: String name

    2. Prints: Hi, [name]!

  2. Create another method named add that:

    1. Takes two parameters: int a and int b

    2. Returns the sum of the two numbers

  3. Inside main:

    1. Call sayHiTo using your name

    2. Call add with two numbers and store the result

    3. Print the result in this format: Sum is: [result]

Hint

  • Use void for methods that only print

  • Use return when a method sends a value back

  • Method calls happen inside main

Challenge: Create a Method

Methods let you group code into reusable actions.

In this challenge, you’ll create two methods and call them from main.

Your tasks

  1. Create a method named sayHiTo that:

    1. Takes one parameter: String name

    2. Prints: Hi, [name]!

  2. Create another method named add that:

    1. Takes two parameters: int a and int b

    2. Returns the sum of the two numbers

  3. Inside main:

    1. Call sayHiTo using your name

    2. Call add with two numbers and store the result

    3. Print the result in this format: Sum is: [result]

Hint

  • Use void for methods that only print

  • Use return when a method sends a value back

  • Method calls happen inside main

Java
public class Main {
public static void main(String[] args) {
// Write your code here
}
}