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.