Advertisement
SergeyPGUTI

7.2.6

Nov 26th, 2015
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.46 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main {
  3.  
  4.  
  5.     static int  wordNumber(String a)
  6.     {
  7.         int words=0;
  8.        for(int i=0,Length=a.length();i<Length;i++)
  9.        {
  10.            if (a.charAt(i)==' ') words++;
  11.        }
  12.         if (words>0) words++;
  13.         return words;
  14.     }
  15.  
  16.     public static void main(String[] args) {
  17.         Scanner in = new Scanner(System.in);
  18.         String a=in.nextLine();
  19.         System.out.println(wordNumber(a));
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement