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
Create a method named
sayHiTothat:Takes one parameter:
String namePrints:
Hi, [name]!
Create another method named
addthat:Takes two parameters:
int aandint bReturns the sum of the two numbers
Inside
main:Call
sayHiTousing your nameCall
addwith two numbers and store the resultPrint the result in this format:
Sum is: [result]
Hint
Use
voidfor methods that only printUse
returnwhen a method sends a value backMethod 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
Create a method named
sayHiTothat:Takes one parameter:
String namePrints:
Hi, [name]!
Create another method named
addthat:Takes two parameters:
int aandint bReturns the sum of the two numbers
Inside
main:Call
sayHiTousing your nameCall
addwith two numbers and store the resultPrint the result in this format:
Sum is: [result]
Hint
Use
voidfor methods that only printUse
returnwhen a method sends a value backMethod calls happen inside
main