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...
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
oneandtwoin its input. Arguments are pass by value to the method. -
Has a
checkvariable whose value gets updated as explained below. -
Adds
num1andnum2, and checks if their sum is less than 100 in which case- Sets the value of the
checkvariable to 0.
- Sets the value of the
-
If sum is greater than 100
- Sets the value of the
checkvariable to 1.
- Sets the value of the
-
If sum is equal to 100
- Sets the value of the
checkvariable to 2.
- Sets the value of the
-
In the end, it will
returnthe check variable.
Example
Input: 4, 80
The console should display the follolwing:
Note: In the above case the method should set
checkto 0.
Write your code below. It is recommended that you try solving the exercise yourself before viewing the solution.
Good Luck!