Java Strings Introduction

  • + 0 comments

    import java.io.; import java.util.;

    public class Solution {

    public static void main(String[] args) {
    
        Scanner sc=new Scanner(System.in);
        String A=sc.next();
        String B=sc.next();
        /* Enter your code here. Print output to STDOUT. */
    
        // 1. Sum the lengths of A and B
        System.out.println(A.length() + B.length());
    
        // 2. Determine if A is lexicographically larger than B
        String[] words = new String[] {A, B};
        Arrays.sort(words);
        if (words[0] == A) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    
        // 3. Capitalize the first letter in A and B and print them on a single line separeted by space
        String ACapitalized = A.substring(0, 1).toUpperCase() + A.substring(1);
        String BCapitalized = B.substring(0, 1).toUpperCase() + B.substring(1);
        System.out.print(String.format("%s %s", ACapitalized, BCapitalized));
    }
    

    }