-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfreq.java
More file actions
37 lines (32 loc) · 977 Bytes
/
Copy pathfreq.java
File metadata and controls
37 lines (32 loc) · 977 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
/*
* File : freq.java
* Description : check frequency of a character in a string
* Author : Alene Elsa
* Version : 1.0
* Date : 29/09/23
*/
import java.util.Scanner;
public class freq{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter the string");
String input=sc.next();
System.out.println("enter the character to be searched");
char checkMe=sc.next().charAt(0);
int CharCount=CheckFreq(input,checkMe);
System.out.println(" frequency of given character is:" +CharCount);
}
/*function receives string as input
* return frequency of the character
*/
static int CheckFreq (String input,char checkMe) {
char[]charArray=input.toCharArray();
int CharCount=0;
for(int i=0;i<input.length();i++) {
if (charArray[i]==checkMe) {
CharCount++;
}
}
return CharCount;
}
}