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.
- Prepare
- Java
- Strings
- Java Strings Introduction
- Discussions
Java Strings Introduction
Java Strings Introduction
+ 0 comments public class Solution {
public static void main(String[] args) { Scanner sc=new Scanner(System.in); String A=sc.next(); String B=sc.next(); int result; result = A.length()+B.length(); System.out.println(result); int res = A.compareTo(B); if(res>0){ System.out.println("Yes"); }else System.out.println("No"); String FLA = A.substring(0,1); String RFA = A.substring(1); String RA = FLA.toUpperCase()+RFA; System.out.print(RA+ " "); String FLB = B.substring(0,1); String RFB = B.substring(1); String RA1 = FLB.toUpperCase()+RFB; System.out.print(RA1 + ""); }
}
+ 0 comments import java.io.; import java.util.;
public class Solution {
public static void main(String[] args) { Scanner sc=new Scanner(System.in); String A=sc.next(); String B=sc.next(); int len_a = A.length(); int len_b = B.length(); int len_sum = len_a + len_b; System.out.println(len_sum); int result = A.compareTo(B); if (result<0){ System.out.println("No"); } else if (result>0) { System.out.println("Yes"); } else{ System.out.println("No"); } String firstletterA = A.substring(0,1); String restofwordA = A.substring(1); String resultA = firstletterA.toUpperCase() + restofwordA; System.out.print(resultA + " "); String firstletterB = B.substring(0,1); String restofwordB = B.substring(1); String resultB = firstletterB.toUpperCase() + restofwordB; System.out.print(resultB); }
}
+ 0 comments I forgot that we have compareTo method. So, I had come up with custom comparator logic, It is not as good as internal implementation of compareTo method but still okay.
int aLen = A.length(), bLen = B.length(); int i=0; while (aLen > 0 && bLen > 0){ if(B.charAt(i)==A.charAt(i)) { i++; bLen--; aLen--; if(aLen == 0 || bLen == 0){ if(aLen == 0 && bLen == 0) System.out.println("Same String"); else if (aLen == 0) System.out.println("No"); else System.out.println("Yes"); } continue; } else if(B.charAt(i)<A.charAt(i)){ System.out.println("Yes"); break; } else { System.out.println("No"); break; } }
+ 0 comments import java.util.Scanner; public class HackerRank_Java_Strings_Introduction { public static void main(String[] args) { Scanner scn = new Scanner(System.in); String A = scn.next(); String B = scn.next(); String upCaseA, upCaseB; int counterA, counterB; // Added the first latter upperCase to the string variable upCaseA = A.substring(0,1).toUpperCase() + A.substring(1).toLowerCase(); upCaseB = B.substring(0,1).toUpperCase() + B.substring(1).toLowerCase(); // Added characters are collected counterA = A.length(); counterB = B.length(); // Collected characters are printed System.out.println(counterA + counterB); if (A.compareTo(B) > 0) { System.out.println("Yes"); } else { System.out.println("No"); } // Print the entered words System.out.println(upCaseA + " " + upCaseB); } }
+ 0 comments Scanner sc=new Scanner(System.in); String A=sc.next(); String B=sc.next(); sc.close(); /* Enter your code here. Print output to STDOUT. */ int sumOfLength = A.length()+B.length(); System.out.println(sumOfLength);
if(A.compareTo(B)>0){ System.out.println("Yes"); } else{ System.out.println("No"); } String s = A.substring(0,1).toUpperCase() + A.substring(1); String y= B.substring(0,1).toUpperCase() + B.substring(1); System.out.print(s+" "+y);
Load more conversations
Sort 993 Discussions, By:
Please Login in order to post a comment