Skip to content

Instantly share code, notes, and snippets.

@mariiaKolokolova
Created May 6, 2020 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariiaKolokolova/9797494789e4eaa4d25c4ddda02bee63 to your computer and use it in GitHub Desktop.
Save mariiaKolokolova/9797494789e4eaa4d25c4ddda02bee63 to your computer and use it in GitHub Desktop.
package maricka.kolokolova;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Input string:");
String str = sc.nextLine();
System.out.println("Your string contains " + countWords(str) + " words");
sc.close();
}
static int countWords(String str) {
String[] array = str.split(" ");
int res = array.length;
return res;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment