Hacker Rank | Java Strings Introduction
Problem:
Given two strings of lowercase English letters, and , perform the following operations:
- Sum the lengths of and .
- Determine if is lexicographically larger than (i.e.: does come before in the dictionary?).
- Capitalize the first letter in and and print them on a single line, separated by a space.
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();
/* Sum of lengths of two strings */
int l = A.length()+B.length();
System.out.println(l);
/*Determine if is lexicographic-ally larger than (i.e.: does come before in the dictionary?)*/
for(int i=0;i<A.length();i++)
{
char x,y;
x=A.charAt(i);
y=B.charAt(i);
int a =x,b=y;
if(a>b)
{
System.out.println("Yes");
break;
}
else{
System.out.println("No");
break;}
}
//Changing first letter to Upper Case i.e Making First letter capital
System.out.println(A.substring(0, 1).toUpperCase() + A.substring(1) +
" "+ B.substring(0, 1).toUpperCase() + B.substring(1));
}
}
No comments
Post a Comment