Java Strings Introduction

  • + 2 comments

    What is wrong with the code below? It failed all test cases

    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. */
            System.out.println(A.length() + B.length());
            char[] CA = A.toCharArray();
            char[] CB = B.toCharArray();
    
            int compareLength = (A.length() < B.length()) ? A.length() : B.length();
            boolean isABigger = false;
    
            for (int i = 0; i < compareLength; i++) {
                if (CA[i] > CB[i]) {
                    isABigger = true;
                    break;
                }
            }
    
            if (isABigger) {
                System.out.println("Yes");
            }
            else {
                System.out.println("No");
            }
        }