[HackerRank] Java Strings Introduction
https://www.hackerrank.com/challenges/java-strings-introduction/problem?isFullScreen=true
Solution
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();
//Step one
System.out.println(A.length() + B.length());
// Step two
if (A.compareTo(B) > 0) {
System.out.println("Yes");
} else {
System.out.println("No");
}
// Step three
String[] arrA = A.split("");
arrA[0] = arrA[0].toUpperCase();
String[] arrB = B.split("");
arrB[0] = arrB[0].toUpperCase();
A = String.join("", arrA);
B = String.join("", arrB);
System.out.println(A + " " + B);
sc.close();
}
}
Another Solution
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();
System.out.println(A.length() + B.length());
System.out.println(A.compareTo(B) > 0 ? "Yes" : "No");
System.out.println(A.substring(0, 1).toUpperCase() + A.substring(1, A.length()) + " " + B.substring(0, 1).toUpperCase() + B.substring(1, B.length()))
sc.close();
}
}
Leave a comment