Counting no of words in a String

 import java.util.Scanner;


public class PrintTotalWords {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Input the string: ");
String str = sc.nextLine();

System.out.print("Number of words in the string: " + count_Words(str) + "\n");
}

public static int count_Words(String str) {
int count = 0;
if (!(" ".equals(str.substring(0, 1))) || !(" ".equals(str.substring(str.length() - 1))))
{
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == ' ') {
count++;
}
}
count = count + 1; // It will count only spaces. 1 is added for the last word to be counted
}
return count; // returns 0 if string starts or ends with space " ".
}
}

Google Script for Data Entry Form in Google Spreadsheet

// function to validate the entry made by user in user form function validateEntry (){ // declare a variable and referernece of active goog...