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






Answered By
6 Likes
Related Questions
How is call-by-value way of function invoking different from call-by-reference way ? Give appropriate examples supporting your answer.
What is the output of the following program ? Justify your answer.
class Check { public static void chg (String (nm) ) { nm = "Aamna" ; // copy "Aamna" to nm } public void test( ) { String name= "Julius"; System.out.println (name); chg(name); System.out.println(name); } }Write a complete Java program that invokes a function satis() to find whether four integers a, b, c, d sent to satis( ) satisfy the equation a3 + b3 + c3 = d3 or not. The function satis( ) returns 0 if the above equation is satisfied with the given four numbers otherwise it returns -1.
Write a program that uses a method power( ) to raise a number m to power n. The method takes int values for m and n and returns the result correctly. Use a default value of 2 for n to make the function calculate squares when this argument is omitted. Write a main( ) method to get the value of m and n to display the calculated result.