Java Strings Introduction

Sort by

recency

|

1229 Discussions

|

  • + 0 comments

    Solution for the problem

    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. */
    
        int sum = A.length() + B.length();
        System.out.println(sum);
        if(A.charAt(0) > B.charAt(0)){
                System.out.println("Yes");
        }else{
                System.out.println("No");
        }
        System.out.println(A.substring(0,1).toUpperCase()+A.substring(1) + " " + B.substring(0,1).toUpperCase()+B.substring(1));
    
    
    }
    
  • + 0 comments

    import java.io.; import java.util.;

    public class Solution { public static String capitalize(String str){ StringBuilder capitalize = new StringBuilder(); char firstChar = str.charAt(0); capitalize.append(Character.toTitleCase(firstChar)).append(str.substring(1)); return capitalize.toString(); }

    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.charAt(0)>B.charAt(0)) System.out.println("Yes");
        else System.out.println("No");
        System.out.println(capitalize(A) + " " + capitalize(B));
    }
    

    }

  • + 0 comments
    import java.io.*;
    import java.util.*;
    
    public class Solution {
    
        public static void main(String[] args) {
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        
            Scanner sc = new Scanner(System.in);
            
            String a = sc.nextLine();
            String b = sc.nextLine();
            
            int k = a.length() + b.length();
            boolean f = a.compareTo(b) > 0 ; 
            String res = a.substring(0,1).toUpperCase() + a.substring(1) 
                                + " " + b.substring(0,1).toUpperCase() + b.substring(1);
            
            System.out.println(k);
            System.out.println( f ? "Yes" : "No" );
            System.out.println( res );
        }
    }
    
  • + 0 comments

    Solution code :-

    import java.io.*;
    import java.util.*;
    
    public class Solution {
        public static String capitalize(String str){
            StringBuilder capitalize = new StringBuilder();
            char firstChar = str.charAt(0);
    				capitalize.append(Character.toTitleCase(firstChar)).append(str.substring(1));
            return capitalize.toString();
        }
    
        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.charAt(0)>B.charAt(0)) System.out.println("Yes");
            else System.out.println("No");
            System.out.println(capitalize(A) + " " + capitalize(B));
        }
    }
    
  • + 0 comments

    Solution in Java

    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 total = A.length()+B.length();
            System.out.println("" + total);
            
            //Just printing the total without using a new variable
            //System.out.println("" +(A.length()+B.length()));
            
            if(A.charAt(0) > B.charAt(0)){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
            /*We create a new string. We use substring and convert the first
            letter of the string and then we add the rest of the string
            */
            
            String cap_A = A.substring(0,1).toUpperCase() + A.substring(1);
            String cap_B = B.substring(0,1).toUpperCase() + B.substring(1);
    
    
            System.out.println(cap_A+" "+ cap_B);
        }
    }