design a function char max char(char,char)-to return the Smallest character from the arguments
Answers
Answer:
class prog{
char maxchar(char a,char b)
{ int c=(int)a; \* dynamic data conversion to find the ASCII code of the character*\
int d=(int)b;
char q=(c>d)?a:b;
return q;
}}
Answer:
import java.util.*;
public class MAXCHARACTER
{
static char maxChar(char a,char b)
{
int ascii1=(int)a;
int ascii2=(int)b;
if(ascii1<ascii2)
{
System.out.println("The Smaller Character is "+(char)ascii1);
return (char)ascii1;
}
else
{
System.out.println("The Smaller Character is "+(char)ascii2);
return (char)ascii2;
}
}
public static void main(String args[])
{
Scanner scr=new Scanner(System.in);
System.out.print("Enter first Character :");
char a=scr.next().charAt(0);
System.out.print("Enter second Character :");
char b=scr.next().charAt(0);
char max=maxChar(a,b);
}
}
I have uploaded the Output also
By Amitesh Das