forked from builder-of-web3/HackR_Java_Code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava Strings Introduction
More file actions
56 lines (43 loc) · 1.89 KB
/
Java Strings Introduction
File metadata and controls
56 lines (43 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Given two strings of lowercase English letters, AA and BB, perform the following operations:
Sum the lengths of AA and BB.
Determine if AA is lexicographically larger than BB (i.e.: does BB come before AA in the dictionary?).
Capitalize the first letter in AA and BB and print them on a single line, separated by a space.
Input Format
Two strings, the first being AA and the second being BB. They are comprised of lowercase English letters (no symbols or spaces) and may not be on the same line.
Output Format
There are three lines of output:
For the first line, sum the lengths of AA and BB.
For the second line, write Yes if AA is lexicographically larger than BB or No if it is not.
For the third line, capitalize the first letter in both AA and BB and print them on a single line, separated by a space.
Sample Input
hello
java
Sample Output
9
No
Hello Java
Explanation
String AA is "hello" and BB is "java".
AA has a length of 55, and BB has a length of 44; the sum of their lengths is 99.
When sorted alphabetically/lexicographically, "hello" comes before "java"; therefore, AA is not larger than BB and the answer is NO.
When you capitalize the first letter of both AA and BB and then print them separated by a space, you get "Hello Java".
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. */
System.out.println(A.length()+B.length());
int i = A.compareTo(B);
if(i>0){
System.out.println("Yes");
} else{
System.out.println("No");
}
String atemp = A.substring(0,1).toUpperCase()+A.substring(1);
String btemp = B.substring(0,1).toUpperCase()+B.substring(1);;
System.out.println(atemp+" "+btemp);
}
}