Challenge 1: Method to Check Sum
In this challenge, you will implement a method which checks the Sum of two integers.
We'll cover the following
Problem statement
Write a static method checkSum
that adds two integer arguments and returns 0, 1 or 2.
-
Takes two integers
one
andtwo
in its input. Arguments are pass by value to the method. -
Has a
check
variable whose value gets updated as explained below. -
Adds
num1
andnum2
, and checks if their sum is less than 100 in which case- Sets the value of the
check
variable to 0.
- Sets the value of the
-
If sum is greater than 100
- Sets the value of the
check
variable to 1.
- Sets the value of the
-
If sum is equal to 100
- Sets the value of the
check
variable to 2.
- Sets the value of the
-
In the end, it will
return
the check variable.
Example
Input: 4, 80
The console should display the follolwing:
Note: In the above case the method should set
check
to 0.
Write your code below. It is recommended that you try solving the exercise yourself before viewing the solution.
Good Luck!
Get hands-on with 1400+ tech skills courses.