-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfreq.java
More file actions
37 lines (37 loc) · 733 Bytes
/
freq.java
File metadata and controls
37 lines (37 loc) · 733 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
35
36
37
import java.util.Scanner;
class freq
{
public static void main(String []args)
{
int v=0,cn=0,f=0;
String str;
Scanner sc= new Scanner(System.in);
System.out.print("Enter the string - ");
str = sc.nextLine();
for(char c='a';c<='z';c++)
{
for(int i=0;i<str.length();i++)
{
if(str.substring(i,i+1).equalsIgnoreCase(Character.toString(c)))
{
f++;
if(str.substring(i,i+1).matches("(A|E|I|O|U|a|e|i|o|u)"))
{
v++;
}
else
{
cn++;
}
}
}
if(f!=0)
{
System.out.println("Number of "+c+" or " +Character.toUpperCase(c)+" - "+f);
f=0;
}
}
System.out.println("Number of vowels - "+v);
System.out.println("Number of consonents - "+cn);
}
}