fork download
  1. import java.util.Scanner;
  2. public class Main{
  3. public static void main(String args[]){
  4. Scanner sc = new Scanner(System.in);
  5. String words = sc.nextLine();
  6. int len = words.length();
  7. int cnt = 0;
  8. for(int i=0;i<len;i++) {
  9. char word = words.charAt(i);
  10. if(word == ' ')
  11. cnt++;
  12. }
  13. sc.close();
  14. System.out.println(cnt+1);
  15. }
  16. }
  17.  
  18.  
  19.  
Success #stdin #stdout 0.13s 51564KB
stdin
 The first character is a blank
stdout
7