...

/

Solution Review: Method to Check Sum

Solution Review: Method to Check Sum

In this review, solution of the challenge 'Method to Check Sum' from the previous lesson is provided.

Solution: Do you know your maths? #

Press + to interact
class challenge_one{
public static int checkSum(int one, int two){
//Write your code here
//Declare the necessary variable
int check;
int sum= one+two;
if(sum<100)
check = 0;
else if(sum>100)
check=1;
else
check=2;
//Change the return variable as well
return check;
}
public static void main(String[] args){
int answer=checkSum(100,110);
System.out.println("The value of check is: "+answer);
answer=checkSum(100,0);
System.out.println("The value of check is: "+answer);
answer=checkSum(100,-110);
System.out.println("The value of check is: "+answer);
}
}

Understanding the code

Line 5: Declare a variable called check which will store the integer value 0,1 or 2 ...