프로그래밍/백준

1152 단어의 개수

게으른구름 2017. 10. 7. 00:07
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import java.util.*;
 
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String in = sc.nextLine();
        in = in.trim();
        if(in.isEmpty()) {
            System.out.println(0);
        }
        else {
            int count = 1;
            for(int i=1; i<in.length(); i++) {
                if(in.charAt(i) == ' ' && in.charAt(i+1!= ' ')
                    count++;
            }
            System.out.println(count);
        }
    }
}
cs