Showing posts with label letters counter in java. Show all posts
Showing posts with label letters counter in java. Show all posts

Monday, February 23, 2015

Count Letters,Numbers and Spacing Program in Java

In this simple article I would like to share with you my avid reader a program that I wrote in Java as my programming language I called this program Count Letters, Numbers and Spacing Program. What this program will do is to ask the user to enter a sentence and then our program will count how many capital letters, lowercase letters, digits and spacing in our given sentence. I am using ASCII decimal values for letters, numbers and spacing in my program. I hope you will my work useful in your learning in Java programming.

If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com.

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360



Sample Output of Our Program


Program Listing

import java.util.Scanner;

public class count {

    public static void main(String[] args)
      {
        char ch;
        String str;

        int uppercase=0,lowercase=0, digits=0,space=0;

        Scanner in = new Scanner(System.in);

        System.out.println("==============================================");
        System.out.println("||Count Letters,Numbers and Spacing Program ||");
        System.out.println("==============================================");
        System.out.print("\n");
System.out.print("Enter a Sentence :=>");
        str = in.nextLine();
        for(int i=0;i<str.length();i++)
        {
            ch = str.charAt(i);
            int asciivalue = (int)ch;

          if(asciivalue >=65 && asciivalue <=90){
                uppercase++;
            }
            else if(asciivalue >=97 && asciivalue <=122){
                lowercase++;
            }
            else if(asciivalue >=48 && asciivalue <= 57){
    digits++;
            }
            else if(asciivalue >=32){
    space++;
            }
        }
       System.out.println("\n\n");
       System.out.println("=======================");
       System.out.println("||  DISPLAY RESULT   ||");
       System.out.println("=======================");
       System.out.println("\n");
       System.out.println("Number of UpperCase Letter(s) : " + uppercase + ".");
       System.out.println("Number of LowerCase Letter(s) : " + lowercase + ".");
       System.out.println("Number of Digit(s)            : " + digits + ".");
       System.out.println("Number of Spacing             : " + space + ".");
       System.out.println("\n");
       System.out.println("\t ===== END OF PROGRAM ======");
       System.out.println("\n");
    }
}