import java.io.InputStreamReader;
public class StringInspection {
public static void main(String[] args) throws Exception {
String s;
System.out.println("enter a sentence-->");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
s = br.readLine();
int length = s.length();
int letters = 0;
int numbers = 0;
int spaces = 0;
for (int i = 0; i < length; i++) {
char ch;
ch = s.charAt(i);
if (Character.isLetter(ch)) {
letters++;
} else {
if (Character.isDigit(ch)) {
numbers++;
} else {
if (Character.isWhitespace(ch)) {
spaces++;
} else
continue;
}
}
}
System.out.println("Number of letters::" + letters);
System.out.println("Number of digits::" + numbers);
System.out.println("Number of white spaces:::" + spaces);
}
}
enter a sentence--->
i am james bond 007
Number of characters: : 12
Number of digits:: 3
Number of white spaces::: 4
No comments:
Post a Comment