Print Capital String Program in Java


import java.util.Scanner;

public class PrintCapitalString
{
    public static void main(String[] args)
    {
        String st,wd="",shortSt="";
        int l;
        Scanner sc=new Scanner(System.in);
        
        System.out.print("Enter String: ");
        st=sc.nextLine();
        
        st=st+" ";
        
        l=st.length();
        for (int i = 0; i < l; i++)
        {
            if(st.charAt(i)==' ')
            {
                if(Character.isUpperCase(wd.charAt(0)))
                {
                    System.out.println(wd);
                }              
                wd="";
            }
            else
            {
                char ch;
                ch=st.charAt(i);
                wd=wd+ch;
            }
        }
        
    }
}


Output:

Enter String: I love my India
I
India
learn java study java