//main class name, "DominantDemo"
public class DominantDemo {
//Method definition of "dominant"
public static boolean dominant(int first, int second, int third) {
// Checks whether the first number is greater
//than the sum of the other two variables. If it
//is correct then returns true.
if (first > (second + third))
return true;
// Checks whether the second number is greater
//than the sum of the other two variables. If it
//is correct then returns true.
else if (second > (first + third))
return true;
// Checks whether the third number is greater
//than the sum of the other two variables. If it
//is correct then returns true.
else if (third > (first + second))
return true;
// Since, none of the number is greater than the
//sum of the other two variables, return false.
else
return false;
}
/*****************************************************
* The main method is used to call the dominant() *
* method and store the return value in ans. Finally, *
*it prints the value stored in ans is true or false. *
*****************************************************/
// Create a main() method to call the dominant() method
//and display the result.
public static void main(String[] args) {
//Call the function
boolean ans = dominant(4, 9, 2);
//Display output
System.out.println(ans);
}
}
Comments
Leave a comment