Skip to content

Instantly share code, notes, and snippets.

@kryvoboker
Created May 14, 2020 14:56
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 kryvoboker/017cd7c403624425f02209576c58de52 to your computer and use it in GitHub Desktop.
Save kryvoboker/017cd7c403624425f02209576c58de52 to your computer and use it in GitHub Desktop.
HomeWork6
import java.util.Arrays;
import java.util.Scanner;
/**
*
* @author kamaz
*/
public class Main {
public static void main(String [] args) {
String text = null;
text = scanner(text);
int a = countWords(text);
System.out.println(a);
}
public static int countWords(String text) {
int n = 0;
char [] letterArray = text.toCharArray();
for (char i : letterArray) {
if (i == ' ') {
n++;
}
}
return n + 1;
}
public static String scanner(String text) {
Scanner sc = new Scanner(System.in);
text = sc.nextLine();
return text;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment