Friday , February 23 2018
Home / java programs / Java Program to Find the characters count in String

Java Program to Find the characters count in String

Here we are going to write a program to find the characters count in String using Java.

Find the characters count in String :

import java.util.Scanner;

public class StringCharcterCountExample {

    public static void main(String a[]) throws Exception {

        int count = 0;
        System.out.println("Enter a String");
        Scanner s1 = new Scanner(;
        String inputValue = s1.nextLine();
        System.out.println("Enter a charcter to count");
        char c = (char);

        if (inputValue != null && !inputValue.equals("")) {

            char[] ch1 = inputValue.toCharArray();
            for (int i = 0; i < ch1.length; i++) {

                if (ch1[i] == c) {
            System.out.println("The '"+c+"' is available in "+
                     count+" times.");

Output :

Enter a String
Enter a charcter to count : t
The ‘t’ is available in 3 times.

About chandrashekhar

Hi Folks, you have reach this so far, that shows you like what you are learning. Then why don't you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,


Java program to find sum of digits

In this Java programming tutorials, I am going to show you how to calculate sum …

Leave a Reply

Your email address will not be published. Required fields are marked *