Exercise 1: Function To Check Sum

In this exercise, you have to write a code to add integers and return their sum using the pass by value method

We'll cover the following

Problem Statement

Write a method checkSum which

  • Takes two integers num1 and num2.

    • pass by value method is used to pass the arguments to method.
  • Has a check variable whose value gets updated as explained below.

  • Adds num1 and num2, and checks if their sum is less than 100 in which case

    • it prints sum is less than 100.
    • sets the value of the check variable to 0.
  • If sum is greater then 100

    • it prints sum is greater than 100.
    • sets the value of the check variable to 1.
  • If sum is equal to 100

    • it prints sum is equal to 100
    • sets the value of the check variable to 2.
  • At 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.

Get hands-on with 1200+ tech skills courses.