Java Program to compare two Strings lexicogrphically , print the sum of their lengths and print them with with their first letter with changed case - HackerRank


 

// Program by Akash Tripathi (@proakash256) 
import java.util.*;
public class String_Introduction
{
    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        String A=sc.next();
        String B=sc.next();
        System.out.printf("%d\n" , (A.length() + B.length()));
        if(A.compareTo(B) >= 0)
            System.out.println("Yes");
        else
            System.out.println("No");
        if(Character.isLowerCase(A.charAt(0)) == true)
            A = A.replace(A.charAt(0) ,
Character.toUpperCase(A.charAt(0)));
        else
            A = A.replace(A.charAt(0) ,
Character.toLowerCase(A.charAt(0)));
        if(Character.isLowerCase(B.charAt(0)) == true)
            B = B.replace(B.charAt(0) ,
Character.toUpperCase(B.charAt(0)));
        else
            B = B.replace(B.charAt(0) ,
Character.toLowerCase(B.charAt(0)));
        System.out.printf("%s %s" , A , B);
        sc.close();
    }
}


Comments