Created
May 14, 2020 14:56
-
-
Save kryvoboker/017cd7c403624425f02209576c58de52 to your computer and use it in GitHub Desktop.
HomeWork6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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