-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringAnalizer.java
More file actions
35 lines (29 loc) · 940 Bytes
/
StringAnalizer.java
File metadata and controls
35 lines (29 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.util.*;
public class StringAnalizer
{
public static void main(String[] args)
{
String input;
char[] array;
int letters = 0;
int digits = 0;
int whitespaces = 0;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a string: ");
input = keyboard.nextLine();
array = input.toCharArray();
for (int i = 0; i < array.length; i++)
{
if (Character.isLetter(array[i]))
letters++;
else if (Character.isDigit(array[i]))
digits++;
else if (Character.isWhitespace(array[i]))
whitespaces++;
}
System.out.println(" The string contains " +
letters + " letters, "+
digits + " digits, and " +
whitespaces + " whitspaces characters.");
}
}