Computer Science, asked by williamjamir, 2 months ago

Write a program to count the number of times a character appears in a given
string.​

Answers

Answered by amansarrafas24payxgs
2

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