View Code of Problem 58

import java.util.Scanner;
public class Main {
	public static void main(String[] args) {	
		Scanner scan = new Scanner(System.in);
		String s = scan.nextLine();
		int count=0;
		for(int i = 1;i<s.length();i++) {
			char c = s.charAt(i);
			char cc = s.charAt(i-1);
			if(c==' '&&cc!=' ') {
				count++;
			}
		}
		System.out.println(count);
		scan.close();
		}
}

Double click to view unformatted code.


Back to problem 58