Advertisement
chillurbrain

13.6. Количество слов в тексте.

May 26th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.46 KB | None | 0 0
  1. package untitled;
  2.  
  3. import java.util.HashSet;
  4. import java.util.Scanner;
  5.  
  6. public class Main {
  7.  
  8.     public static void main(String[] args) {
  9.         Scanner sc = new Scanner(System.in);
  10.         int counter = 0;
  11.         HashSet<String> set = new HashSet<>();
  12.         String string = sc.nextLine();
  13.  
  14.         for (String s : string.split(" "))
  15.             if (!s.trim().equals(""))
  16.                 set.add(s);
  17.         System.out.println(set.size());
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement