Java Strings Introduction ⬀
"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, and , perform the following operations:
- Sum the lengths of
AandB. - Determine if
Ais lexicographically larger thanB(i.e.: doesBcome beforeAin the dictionary?). - Capitalize the first letter in
AandBand print them on a single line, separated by a space.
The first line contains a string A. The second line contains another string B.
The strings are comprised of only lowercase English letters.
There are three lines of output:
- For the first line, sum the lengths of
AandB. - For the second line, write
YesifAis lexicographically greater thanBotherwise printNoinstead. - For the third line, capitalize the first letter in both
AandBand print them on a single line, separated by a space.
hello
java
9
No
Hello Java
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, A is not greater than B 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".