We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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. */
//first line, sum the lengths of A and B
int lengthOfAB = A.length() + B.length();
System.out.println(lengthOfAB);
//second line, write "Yes" if A is lexicographically greater than B otherwise "No"
int compareTo = A.compareToIgnoreCase(B);
if(compareTo != 0){
System.out.println("No");
} else {
System.out.println("Yes");
}
//third line, capitalize the first letter in both A and B and print them on a single ine seperated by a space
//I want to grab the first letter from A and B no matter the input and capatalize the input but also print the rest of the string with a space seperated between them
char aCapitalize = A.charAt(0);
char bCapitalize = B.charAt(0);
String aStringCapitalize = String.valueOf(aCapitalize).toUpperCase();
String bStringCapitalize = String.valueOf(bCapitalize).toUpperCase();
System.out.print(aStringCapitalize + A.substring(1) + " " + bStringCapitalize + B.substring(1));
//test case 1
//input : java
// java
//Expected output
//8
//No
//Java Java
//Test Case 2
//input: java
// hello
//Expected output
//9
//Yes
//Java Hello
//both test cases work but results do fail from hackerank not sure why put custom test case and passes both
//code by: @jesse_aluiso
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Strings Introduction
You are viewing a single comment's thread. Return to all comments →
import java.io.; import java.util.;
public class Solution {
}