package simpleproblems;

public class CountWords {
	public static int countWords(String s) {
		int r = 0;
		char[] c = s.toCharArray();
		for (int i=0; i< c.length -1; i++) {
			if (c[i] != ' ' && c[i+1] == ' ') {
				r ++;
			}
		}
		if (c[c.length-1] != ' ') {  // If the last character is not a space, add this word in.
			r ++;
		}
		return r;
	}

	public static void main(String[] args) {
		System.out.println(CountWords.countWords("Let there be light, and there is light."));
	}

}
