Problem Name: Java Strings Introduction

Problem Link:

In this HackerRank Functions in Java programming problem solution,

"A string is traditionally a sequence of characters, either as a literal constant or as some kind of variable." — Wikipedia: String (computer science)


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:

  1. Sum the lengths of A and B.
  2. Determine if A is lexicographically larger than B (i.e.: does B come before A in the dictionary?).
  3. Capitalize the first letter in A and B nd 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


Sample Output 0

Hello Java




Code Examples

#1 Code Example with Java Programming

Code - Java Programming

import java.util.Scanner;

public class Solution{
	public static void main(String[] args){
		Scanner input = new Scanner(;

		String a =;
		String b =;

		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()) );
Copy The Code & Try With Live Editor


[Solved] Java Currency Formatter in Java solution in Hackerrank - Hacerrank solution Java
[Solved] Java Substring in Java solution in Hackerrank - Hacerrank solution Java