ICSE Class 10 Computer Applications Question 36 of 43

User-Defined Methods — Question 36

Back to all questions
36
Question

Question 34

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.

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;
    }
    
}
Output
BlueJ output of KboatCompareChar.java
BlueJ output of KboatCompareChar.java
BlueJ output of KboatCompareChar.java
BlueJ output of KboatCompareChar.java
BlueJ output of KboatCompareChar.java
BlueJ output of KboatCompareChar.java
Answer