public class CountWords {
public static void main(String[] args) {
String s = " i am hehao ";
//wordCount(s);
wordCount1(s);
}
public static void wordCount(String str){
String[]s1 = str.trim().split(" ");
System.out.println(s1.length);
}
public static void wordCount1(String str){
int word = 0;
int count = 0;
for(int j=0;j< str.length();j++){
if(str.charAt(j)==' '){
word = 0;
}
else if(word==0){
word=1;
count++;
}
}
System.out.println(count);
}
}