Java Strings Introduction

  • + 0 comments

    I dont believe this is the best solution (for the 3rd request) but can be applied

    public static void main(String[] args) {
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
            Scanner sc= new Scanner(System.in);
            String a = sc.nextLine();
            String b = sc.nextLine();
            
            //Print length
            System.out.println(a.length() + b.length());
            
            //Lexicographically larger
            System.out.println((a.compareTo(b) > 0) ? "Yes" : "No");
            
            //Capitalize first character and print
            String aNew = a.substring(0,1).toUpperCase();
            String bNew = b.substring(0,1).toUpperCase();
            
            if(a.length() > 1) aNew += a.substring(1);
            if(b.length() > 1) bNew += b.substring(1);
            
            System.out.println(aNew + " " + bNew);
        }