fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Scanner in=new Scanner(System.in);
  13. String s=new String();
  14. System.out.println("Enter a line:");
  15. s=" "+in.nextLine().trim();
  16. char c;
  17. int ct=0;
  18. for(int i=1;i<s.length();i++)
  19. {
  20. c=s.charAt(i);
  21. if(c>=65 && c<=90 && s.charAt(i-1) == 32)
  22. {
  23. ct++;
  24.  
  25. }
  26. }
  27. System.out.println("total number of words start with capital letters are :"+ct);
  28. }
  29. }
Success #stdin #stdout 0.13s 321344KB
stdin
Hi hOw are yOu
stdout
Enter a line:
total  number of words start with capital letters are :1