-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfreq_reverse_String.java
More file actions
42 lines (40 loc) · 1.07 KB
/
Copy pathfreq_reverse_String.java
File metadata and controls
42 lines (40 loc) · 1.07 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
import java.util.*;
public class freq_reverse_String {
public static void main(String args[])
{
function obj=new function();
Scanner obj1=new Scanner(System.in);
System.out.println("Enter the string:");
String str=obj1.nextLine();
System.out.println("Enter the character to be find the frequency: ");
char a = obj1.next().charAt(0);
obj1.close();
obj.freq(str,a);
obj.rev(str);
}
}
class function
{
void rev(String str)
{
String rev="";
int len=str.length();
for(int i=len-1;i>=0;i--)
{
rev=rev+str.charAt(i);
}
System.out.println("Reversed string is:"+rev);
}
void freq(String str,char a)
{
int len=str.length();
int frequency=0;
for(int i=0;i<len;i++)
{
if(a==str.charAt(i)){
System.out.println("The character is present at position "+(i+1));
frequency++ ; }
}
System.out.println("Frequency of character is "+frequency) ;
}
}