Count Vowels,Capital letters,small letters,numbers and space in Java


The count to Uppercase, Lowercase, Space, Number, Vowels and Symbols in a String. The using for the ASCII (American Standard Code for Information Interchange) Number. Codes 32-127 are common for all the different variations of the ASCII table, they are called printable characters, represent letters, digits, punctuation marks, and a few miscellaneous symbols.

Source Code

public class countCharacter {
    public static void main(String args[])
    {
        //Program to Count Uppercase,Lowercase,Space,Number,Vowels and Symbols in a String
        StringBuilder a = new StringBuilder("Ram-age is 12@");
        System.out.println(a);
        int upper = 0, lower = 0, space = 0, number = 0, vowels = 0;
        for (int i = 0; i < a.length(); i++) {
            if (a.charAt(i) >= 97 && a.charAt(i) <= 122) {
                lower++;
            }
            if (a.charAt(i) >= 65 && a.charAt(i) <= 90) {
                upper++;
            }
            if (a.charAt(i) == 32) {
                space++;
            }
            if (a.charAt(i) >= 48 && a.charAt(i) <= 57) {
                number++;
            }
            if (a.charAt(i) == 'A' || a.charAt(i) == 'E' || a.charAt(i) == 'I' || a.charAt(i) == 'O' ||
                    a.charAt(i) == 'U' || a.charAt(i) == 'a' || a.charAt(i) == 'e' || a.charAt(i) == 'i' ||
                    a.charAt(i) == 'o' || a.charAt(i) == 'u') {
                vowels++;
            }
        }
        System.out.println("Uppercase   : "+upper);
        System.out.println("Lowercase   : "+lower);
        System.out.println("Space       : "+space);
        System.out.println("Number      : "+number);
        System.out.println("Vowels      : "+vowels);
        System.out.println("Symbols      : "+(a.length()-(upper+lower+space+number)));
    }
}
 

Output

Ram-age is 12@
Uppercase   : 1
Lowercase   : 7
Space       : 2
Number      : 2
Vowels      : 4
Symbols      : 2
To download raw file Click Here

Basic Programs