展开全部
import java.util.Scanner;
public class Demo {
/**
* @param args
*/
public static void main(String[] args) {
62616964757a686964616fe78988e69d8331333337613165String s = "";
Scanner scanner = new Scanner(System.in);
System.out.println("Enter sentence:");
s = scanner.nextLine();
int length = s.length();
int acLength = 0;
int wcLength = 0;
int ntLength = 0;
for(int i=0;i
if((s.charAt(i) >= 'a' && s.charAt(i) <= 'z') || (s.charAt(i) >= 'A' && s.charAt(i) <= 'Z') || (s.charAt(i) >= '0' && s.charAt(i) <= '9')){
acLength++;
}else if(s.charAt(i) == ' '){
wcLength++;
}
}
String ss = s.replaceAll(" +", " ");
ntLength = ss.split(" ").length;
System.out.println("sentence statistics:");
System.out.println(" -Length of sentence: "+length);
System.out.println(" -Alphanumeric characters: "+acLength);
System.out.println(" -Whitespace characters: "+wcLength);
System.out.println(" -Number of tokens: "+ntLength);
}
//The quick BROWN fox jumped over the 2 lazy dogs (or was it 3?).
}
The quick BROWN fox jumped over the 2 lazy dogs (or was it 3?).
sentence statistics:
-Length of sentence: 63
-Alphanumeric characters: 46
-Whitespace characters: 13
-Number of tokens: 14