-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathExp04_3.java
More file actions
66 lines (53 loc) · 1.48 KB
/
Copy pathExp04_3.java
File metadata and controls
66 lines (53 loc) · 1.48 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
60
61
62
63
64
65
66
import java.io.*;
class Exp04_3
{
public static void main(String[] args) throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a string");
String s1=b.readLine();
System.out.println("\nEnter the character to be searched");
char c=(char)b.read();
int count=FindFrequencyCount(s1,c);
System.out.println("\nThe number of appearance of "+c+" is "+count);
ReplaceCharacter(s1);
ReplaceFirstCharacter(s1);
}
public static int FindFrequencyCount(String s1, char c)
{
int n,count=0;
n=s1.length();
for(int i=0;i<n;i++)
{
if (s1.charAt(i)==c)
count++;
}
return(count);
}
public static void ReplaceCharacter(String s1)
{
System.out.println("\nThe new string is "+s1.replace(s1.charAt(0),s1.toUpperCase().charAt(0)));
}
public static void ReplaceFirstCharacter(String s1)
{
System.out.println("\nString before modification: "+s1);
s1.trim();
StringBuffer sb=new StringBuffer();
for(String onestring:s1.split(" "))
{
sb.append(onestring.substring(0,1).toUpperCase() );
sb.append(onestring.substring(1));
sb.append(" ");
}
System.out.println("String after modification: "+sb);
}
}
/* OUTPUT
Enter a string
all the best
Enter the character to be searched
t
The number of appearance of t is 2
The new string is All the best
String before modification: all the best
String after modification: All The Best */