Can someone solve the program
Answers
import java.util.Scanner;
public class HelloWorld{
static void compare(int a,int b)
{
if(a>=b)
System.out.println("Larger is "+a);
else
System.out.println("Larger is "+b);
}
static void compare(char a,char b)
{
if(a>b)
System.out.println("Larger is "+a+" with numeric value "+(int)a);
else
System.out.println("Larger is "+b+" with numeric value "+(int)b);
}
static void compare(String a,String b)
{
if(a.length()>b.length())
System.out.println("Longer is "+a);
if(b.length()>a.length())
System.out.println("Longer is "+b);
if(a.length()==b.length())
System.out.println("Both are equal");
}
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
System.out.println("what do you want to compare? Enter");
System.out.println("1.String 2.cahr 3.int");
int n=sc.nextInt();
switch(n)
{
case 1:
System.out.println("Enter first string");
String a=sc.next();
System.out.println("Enter second string");
String b=sc.next();
compare(a,b);
break;
case 2:
System.out.println("Enter first character");
char c=sc.next(). c h a r A t (0);
System.out.println("Enter second cahracter");
char d=sc.next(). c h a r A t (0);
compare(c,d);
break;
case 3:
System.out.println("Enter first number");
int e=sc.nextInt();
System.out.println("Enter second number");
int f=sc.nextInt();
compare(e,f);
break;
default:
System.out.println("Wrong choice");
}
}
}