File clean-up

This commit is contained in:
KylerSmith
2017-07-09 16:29:00 -07:00
parent 5fec65b247
commit ae7aba0b44
21 changed files with 14 additions and 14 deletions

26
Misc/countwords.java Normal file
View File

@@ -0,0 +1,26 @@
import java.util.Scanner;
/**
* You enter a string into this program, and it will return how
* many words were in that particular string
*
* @author Marcus
*
*/
class CountTheWords{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("Enter your text: ");
String str = input.nextLine();
System.out.println("Your text has " + wordCount(str) + " word(s)");
input.close();
}
public static int wordCount(String s){
if(s.isEmpty() || s == null) return -1;
return s.trim().split("[\\s]+").length;
}
}