Hello Programmers/Coders, Today we are going to share solutions of Programming problems of HackerRank of Programming Language Java . At Each Problem with Successful submission with all Test Cases Passed, you will get an score or marks. And after solving maximum problems, you will be getting stars. This will highlight your profile to the recruiters.
In this post, you will find the solution for Java Strings Introduction-HackerRank Problem. We are providing the correct and tested solutions of coding problems present on HackerRank. If you are not able to solve any problem, then you can take help from our Blog/website.
Use “Ctrl+F” To Find Any Questions Answer. & For Mobile User, You Just Need To Click On Three dots In Your Browser & You Will Get A “Find” Option There. Use These Option to Get Any Random Questions Answer.
Introduction To Java
JAVA was developed by James Gosling at Sun Microsystems Inc in the year 1991, later acquired by Oracle Corporation. It is a simple programming language. Java makes writing, compiling, and debugging programming easy. It helps to create reusable code and modular programs.
Java is a class-based, object-oriented programming language and is designed to have as few implementation dependencies as possible. A general-purpose programming language made for developers to write once run anywhere that is compiled Java code can run on all platforms that support Java. Java applications are compiled to byte code that can run on any Java Virtual Machine. The syntax of Java is similar to c/c++.
Link for the Problem – Java Strings Introduction – Hacker Rank Solution
Java Strings Introduction – Hacker Rank Solution
Objective
“A string is traditionally a sequence of characters, either as a literal constant or as some kind of variable.
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 B come before A 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
Explanation 0
String A is “hello” and B is “java”.
A has a length of 5 , and B has a length of 4; the sum of their lengths is 9 .
When sorted alphabetically/lexicographically, “hello” precedes “java”; therefore, is not greater than and the answer is No
.
When you capitalize the first letter of both A and B and then print them separated by a space, you get “Hello Java”.
Java Strings Introduction – Hacker Rank Solution
import java.util.Scanner; 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()); if (A.compareTo(B) > 0) { System.out.println("Yes"); } else { System.out.println("No"); } A = A.substring(0, 1).toUpperCase() + A.substring(1); B = B.substring(0, 1).toUpperCase() + B.substring(1); System.out.println(A + " " + B); } }
Very interesting subject , appreciate it for posting.