Author Topic: Java program to count number of alphabets and non-alphabets in a string  (Read 1074 times)


  • Administrator
  • Sr. Member
  • *****
  • Posts: 283
Here is the C# program to count number of alphabets and non-alphabets in a string.

Code: (java)
//Source Code Listing

import java.lang.*;
import java.util.*;
class Count_Alphabet
      static public String ReadString()
                  String inpString = "";
                  InputStreamReader input = new InputStreamReader(;
                  BufferedReader reader = new BufferedReader(input);
                  return reader.readLine();
            catch (Exception e)
            return "";
      public static void main(String[] args)
            System.out.println("Program to count the number of alphabets and non-alphabets");
            System.out.print("Enter a string:");
            String input = ReadString();

            int alphabet_count = 0;
            int non_alphabet_count = 0;

            for(int i = 0; i < input.length(); i++)
               if(input.charAt(i) >= 'a' && input.charAt(i) <= 'z')
               else if(input.charAt(i) >= 'A' && input.charAt(i) <= 'Z')
            System.out.format("Number of alphabets: %d\n", alphabet_count);
            System.out.format("Number of Non-alphabets: %d\n", non_alphabet_count);


Program to count the number of alphabets and non-alphabets
Enter a string:welcome to software & finance
Number of alphabets: 24
Number of Non-alphabets: 5


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1