KnowledgeBoat Logo
|

Computer Applications

Write a function that takes two char arguments and returns 0 if both the arguments are equal. The function returns -1 if the first argument is smaller than the second and 1 if the second argument is smaller than the first.

Java

User Defined Methods

14 Likes

Answer

class KboatCompareChar
{
    int compareChar(char c1, char c2)   {
        
        int ret;
        
        if(c1 == c2) 
           ret = 0;
        else if(c1 < c2)
            ret = -1;
        else
            ret = 1;
            
        return ret;
    }
    
}

Variable Description Table

Program Explanation

Output

BlueJ output of Write a function that takes two char arguments and returns 0 if both the arguments are equal. The function returns -1 if the first argument is smaller than the second and 1 if the second argument is smaller than the first.BlueJ output of Write a function that takes two char arguments and returns 0 if both the arguments are equal. The function returns -1 if the first argument is smaller than the second and 1 if the second argument is smaller than the first.BlueJ output of Write a function that takes two char arguments and returns 0 if both the arguments are equal. The function returns -1 if the first argument is smaller than the second and 1 if the second argument is smaller than the first.BlueJ output of Write a function that takes two char arguments and returns 0 if both the arguments are equal. The function returns -1 if the first argument is smaller than the second and 1 if the second argument is smaller than the first.BlueJ output of Write a function that takes two char arguments and returns 0 if both the arguments are equal. The function returns -1 if the first argument is smaller than the second and 1 if the second argument is smaller than the first.BlueJ output of Write a function that takes two char arguments and returns 0 if both the arguments are equal. The function returns -1 if the first argument is smaller than the second and 1 if the second argument is smaller than the first.

Answered By

6 Likes


Related Questions