Java Strings Introduction

  • + 0 comments

    Hi this is the code i submitted and it passed all test cases, but i am confused as to why this line worked (A.compareTo(B) > 1). When i used the line A.compareTo(B) == 1 test case two kept on failing until i made this change by mistake i meant to write 0 (zero) instead of 1 (one).

    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();
        sc.close();
    
        System.out.println(A.length() + B.length());
    
        if(A.compareToIgnoreCase(B) > 1)
                System.out.println("Yes");
            else
                System.out.println("No");
    
        System.out.println(
            A.replace(A.charAt(0), Character.toUpperCase(A.charAt(0)))
            +" "+ B.replace(B.charAt(0), Character.toUpperCase(B.charAt(0))));
    
    }
    

    }