-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathCount Particular character in string
More file actions
46 lines (30 loc) · 1.25 KB
/
Count Particular character in string
File metadata and controls
46 lines (30 loc) · 1.25 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.Arrays;
public class BasicProgram {
// count character
// Newton 0 index
public static int countCharacter (String s , char ch) {
int count = 0;
for(int i=0;i<s.length();i++) {
if(s.charAt(i) == Character.toLowerCase(ch) ) {
count++;
}
}
return count;
}
public static void main(String[] args) {
// String data type which is used to store the data that data should be text
// if enclosed any anything between double quoted symbol that is string
// How to decalre the string
// anything between the '' it will consider that as a character => character should be one
// print and println method only except string or integrer array
System.out.println();
// plus operator in string
// it will concatenate two string or you can say it will add two string into the single string
// I want to calculate the how many type particular character present in given string
String variableName = "Newton";
System.out.println("What are you doing : " +variableName);
// calling count character Method ignore cases
int a = countCharacter(variableName.toLowerCase() , 'n');
System.out.println("Count of character: " + a);
}
}