Question: Complete the following method, which compares two parameters and returns -1, 0, or 1 if the first parameter is less than, equal to, or greater
Complete the following method, which compares two parameters and returns -1, 0, or 1 if the first parameter is less than, equal to, or greater than the second parameter. Note answers are case sensitive.
public int compare(int a, int b) { ______________ result; // declare variable of appropriate type. The variable will get its value then be returned.
if (a______________ = -1; // assignment -1 to which variable?} else ___________ (a _________ b) {// when the two parameters have same value, assign 0 to variable to be returned______________ = 0;} else { // a must be great than b in this caseresult = 1;}_____________ result; //one of the branching keywords.}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
