146k views
5 votes
Design a function char maxChar (char,char)- to return the smallest character from the arguments.

in java please please​

Design a function char maxChar (char,char)- to return the smallest character from-example-1
User Louis Boux
by
5.1k points

1 Answer

5 votes

Answer:

Following are the program to the given question:

public class Main//defining Main method

{

char maxChar (char x1,char x2)//defining a method maxChar that takes two char parameter

{

if(x1<x2)//use if to compare char value

{

return x1;//return first char value

}

else//else block

{

return x2;//return second char value

}

}

public static void main(String[] args)//defining main method

{

char x1,x2;//defining char variable

x1='d';//use char to hold value

x2='a';//use char to hold value

Main ob=new Main();//creating class Object

System.out.println(ob.maxChar(x1,x2));//calling method and prints its return value

}

}

Output:

a

Step-by-step explanation:

In this code, a method "maxChar" is defined that holds two char variable "x1,x2" in its parameters, and use if conditional statement that checks the parameter value and print its return value.

In the main method, two char variable is declared that hold char value and passing the value in the method and prints its return value.

User Vadim Yangunaev
by
5.2k points