The program takes two strings as input from the user. It then performs several operations on these strings, including calculating their combined length, comparing them lexicographically, and formatting them by capitalizing the first letter of each string.
CodeRankGPT is a tool powered by GPT-4 that quietly assists you during your coding interview, providing the solutions you need.
In real-time and absolutely undetectable 🥷
The solution first reads two strings from the user. It then calculates and prints the sum of their lengths. Next, it compares the strings lexicographically, character by character, and prints 'Yes' if the first string is lexicographically greater than the second, and 'No' otherwise. If the strings are equal up to the length of the shorter string, it considers the longer string as greater. Finally, it capitalizes the first letter of each string and prints them.
/**
*
*/
package com.javaaid.hackerrank.solutions.languages.java.strings;
import java.util.Scanner;
/**
*
*/
public class JavaStringsIntroduction {
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());
int l = A.length() > B.length() ? B.length() : A.length();
String str = "";
for (int i = 0; i < l; i++) {
if ((int) (A.toLowerCase()).charAt(i) > (int) (B.toLowerCase()).charAt(i)) {
str = "Yes";
break;
} else if ((A.toLowerCase()).charAt(i) < (B.toLowerCase()).charAt(i)) {
str = "No";
break;
}
}
if (str == "") {
if (A.length() > B.length()) {
str = "Yes";
} else {
str = "No";
}
}
System.out.println(str);
System.out.println((A.toUpperCase()).charAt(0) + A.substring(1, A.length()) + " " + (B.toUpperCase()).charAt(0)
+ B.substring(1, B.length()));
sc.close();
}
}
If you have a HackerRank coding test coming up, you can use CodeRankGPT to your advantage. It will assist you during your interview and help ensure you get the job.
AI is here now, and other candidates might be using it to get ahead and win the job. 🧐
The form has been successfully submitted.