Java Strings Introduction- Hacker Rank Solution

Java Strings Introduction- Hacker Rank Solution

Java Strings Introduction- Hacker Rank Solution
Thursday, 24 September 2020

Java hackerRank solution

 

This exercise is to test your understanding of Java Strings. A sample String declaration:

 

String myString = "Hello World!"

The elements of a String are called characters. The number of characters in a String is called the length, and it can be retrieved with the String.length() method.

 

Given two strings of lowercase English letters,A  and B, perform the following operations:

 

Sum the lengths of  A and B.

Determine if A is lexicographically larger than B  (i.e.: does  come before  in the dictionary?).

Capitalize the first letter in A  and B and print them on a single line, separated by a space.

Input Format

 

The first line contains a string A . The second line contains another string B . The strings are comprised of only lowercase English letters.

 

Output Format

 

There are three lines of output:

For the first line, sum the lengths of  A and B .

For the second line, write Yes if A is lexicographically greater than B otherwise print No instead.

For the third line, capitalize the first letter in both A  and B and print them on a single line, separated by a space.

 

Sample Input 0

 

hello

java

Sample Output 0

 

9

No

Hello Java


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();
        /* Enter your code here. Print output to STDOUT. */
        
        int a = A.length();
        int b = A.length();
        System.out.println(A.length()+B.length());
System.out.println(A.compareTo(B)>0?"Yes":"No");
System.out.println(A.substring(01).toUpperCase()+A.substring(1A.length())+" "+B.substring(01).toUpperCase()+B.substring(1B.length()));
    }

}



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. */
        
        int a = A.length();
        int b = A.length();
        System.out.println(A.length()+B.length());
System.out.println(A.compareTo(B)>0?"Yes":"No");
System.out.println(A.substring(01).toUpperCase()+A.substring(1A.length())+" "+B.substring(01).toUpperCase()+B.substring(1B.length()));
    }

}





Java Strings Introduction- Hacker Rank Solution
4/ 5
Oleh