write a program to count the number of times each characters appear in a given string
ex wool
w = 1
o = 2
l = 3
Answers
Answered by
0
Answer:
import java.util.*;
class Word
{
public void main()
{
Scanner sc = new Scanner (System.in);
System.out.print("Enter String: ");
String str = sc.nextLine();
int count;
int len = str.length();
for(int i = 0;i < len;i++)
{
char ch = str.charAt(i);
count = 0;
for(int j = 0;j < len;j++)
{
char ch1 = str.charAt(j);
if(ch == ch1)
{
count++;
}
}
System.out.println(ch + " = " + count);
}
}
}
I hope you find it useful... If you have any query do comment, I will try to solve it...
Similar questions