-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringfun.java
More file actions
59 lines (57 loc) · 1.51 KB
/
Copy pathStringfun.java
File metadata and controls
59 lines (57 loc) · 1.51 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
50
51
52
53
54
55
56
57
58
59
import java.util.*;
public class Stringfun
{
String str;
void input()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the String");
str=sc.nextLine()+" ";
}
void words()
{
int w=0,v=0,u=0;
for(int i=0;i<str.length();i++)
{
char ch=str.charAt(i);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
v++;
if(ch==' ')
w++;
if(Character.isUpperCase(ch)==true)
u++;
}
System.out.println("Number of words="+w);
System.out.println("Number of vowels="+v);
System.out.println("Number of Upper Case characters="+u);
}
void frequency()
{
int f=0;
char c[]=str.toCharArray();
String s="";
for(int a=0;a<c.length-1;a++)
{
for(int b=a+1;b<c.length;b++)
if(c[a]==c[b]||c[b]==' ')
c[b]='\u0000';
}
for(int d=0;d<c.length;d++)
if(c[d]!='\u0000')
s+=c[d];
str=str.toUpperCase();
s=s.toUpperCase();
for(int i=0;i<s.length();i++)
{
f=0;
char ch=s.charAt(i);
for(int j=0;j<str.length();j++)
{
char ch1=str.charAt(j);
if(ch==ch1)
f++;
}
System.out.println("Frequency of "+ch+" is "+f);
}
}
}