Skip to content

Commit 38fad30

Browse files
NoOfCharacterOccurance
NoOfCharacterOccurance
1 parent fd5a1d8 commit 38fad30

31 files changed

+51
-0
lines changed

bin/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/JavaPrograms/

bin/JavaPrograms/AddTwoInteger.class

0 Bytes
Binary file not shown.

bin/JavaPrograms/Alphabetcheck.class

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

bin/JavaPrograms/Calculator.class

0 Bytes
Binary file not shown.

bin/JavaPrograms/CheckLeapYear.class

0 Bytes
Binary file not shown.

bin/JavaPrograms/EvenOdd.class

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

bin/JavaPrograms/FactorsNumber.class

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

bin/JavaPrograms/FindAsciChar.class

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

bin/JavaPrograms/NumberOfDigits.class

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

bin/JavaPrograms/PowerConcept.class

0 Bytes
Binary file not shown.

bin/JavaPrograms/PrimeNumber.class

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

bin/JavaPrograms/PrintInteger.class

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

bin/JavaPrograms/ReverseANumber.class

0 Bytes
Binary file not shown.

bin/JavaPrograms/ReverseString.class

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

bin/JavaPrograms/SwapNumber.class

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package JavaPrograms;
2+
3+
public class NoOfCharacterOccurance {
4+
static final int maxChar=256;
5+
6+
// using Array
7+
static void getOccurringChar(String str) {
8+
// creating an array of size 256
9+
int count[] = new int[maxChar];
10+
11+
int len = str.length();
12+
13+
// Initialize count array index
14+
for (int i = 0; i < len; i++)
15+
count[str.charAt(i)]++;
16+
17+
// Create an array of given String size
18+
char ch[] = new char[str.length()];
19+
for (int i = 0; i < len; i++) {
20+
ch[i] = str.charAt(i);
21+
int find = 0;
22+
for (int j = 0; j <= i; j++) {
23+
24+
// If any matches found
25+
if (str.charAt(i) == ch[j])
26+
find++;
27+
}
28+
29+
if (find == 1)
30+
System.out.println("Number of Occurrence of " + str.charAt(i) + " is:" + count[str.charAt(i)]);
31+
}
32+
}
33+
// main method
34+
public static void main(String[] args)
35+
{
36+
//String str = "Maish Upadhyay";
37+
//getOccurringChar(str);
38+
39+
// using string library
40+
String input = "Manish Upadhyay";
41+
char search = 'a';
42+
int count =0;
43+
for(int i=0; i<input.length(); i++) {
44+
if(input.charAt(i) == search)
45+
count++;
46+
}
47+
System.out.println("The Character '"+search+"' appears "+count+" times.");
48+
}
49+
50+
}

0 commit comments

Comments
 (0)