- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java program to find the Frequency of a character in a given String
To find the Frequency of a character in a given String
- Read a string from the user.
- Read the character.
- Create an integer variable initialize it with 0.
- Compare each character in the given string with the entered character increment the above created integer variable each time a match occurs.
Example
import java.util.Scanner; public class FrequencyOfACharacter { public static void main(String args[]){ System.out.println("Enter a string value ::"); Scanner sc = new Scanner(System.in); String str = sc.nextLine(); System.out.println("Enter a particular character ::"); char character = sc.nextLine().charAt(0); int count = 0; for (int i=0; i<str.length(); i++){ if(character == str.charAt(i)){ count++; } } System.out.println("Frequency of the give character:: "+count); } }
Output
Enter a string value :: Hi welcome to Tutorialspoint Enter a particular character :: t Frequency of the give character:: 3
- Related Articles
- Java Program to Find the Frequency of Character in a String
- Golang program to find the frequency of character in a string
- C++ Program to Find the Frequency of a Character in a String
- Java Program to Get a Character From the Given String
- Java Program to replace all occurrences of a given character in a string
- Java Program to access character of a string
- Java Program to locate a character in a string
- Python program to find occurrence to each character in given string
- Python program to change character of a string using given index
- C program to find frequency of each digit in a string
- Java Program to replace all occurrences of a given character with new character
- Program to find the index of first Recurring Character in the given string in Python
- Java Program to Replace the Spaces of a String with a Specific Character
- Java program to convert a character array to string
- Java Program to Capitalize the first character of each word in a String

Advertisements