-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringAllCount.java
More file actions
49 lines (47 loc) · 1.24 KB
/
Copy pathStringAllCount.java
File metadata and controls
49 lines (47 loc) · 1.24 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/** A java program to read a string from keyboard and count the total numbers of
* 1 - Capital Letters
* 2 - Small Letters
* 3 - Vowel
* 4 - Consonents
* 5 - Digits
* 6- Words
* 7 - Special characters
* */
import java.util.Scanner;
class StringAllCount
{
public static void main(String[] args)
{
String str;
char ch;
int cl,sl,v,con,dig,wo,spch;
cl=sl=v=con=dig=wo=spch=0;
Scanner sc = new Scanner(System.in);
System.out.print("Enter a sting : ");
str = sc.next();
for(int i =0; i<= str.length();i++)
{
//ch = str.charAt(i);
for(int j = i;j<= str.length();j++)
{
ch = str.charAt(i);
if(ch >= 'A' && ch <= 'Z')
cl++;
else if(ch >= 'a' && ch <= 'z')
sl++;
else if(ch == 'a'||ch == 'e'|| ch == 'i'||ch == 'o' || ch == 'u'||ch == 'A'|| ch == 'E' || ch == 'I'|| ch == 'O'|| ch == 'U' )
v++;
else
con++;
}
}
System.out.print("Your ching : "+str);
System.out.println("Capital Letters : "+cl);
System.out.println("Small Letters : "+sl);
System.out.println("Vowels : "+v);
System.out.println("Consonents : "+con);
System.out.println("Digits : "+dig);
System.out.println("Words : "+wo);
System.out.println("Special Charectors : "+spch);
}
}