//please save this code as Count.java or download the given file and compile it with " javac Count.java " //After successful compilation run this with " java Count" at CMD // Make sure you have java already //installed in your system CODE : : import java.util.*; class Count { public static void main(String m[]) { Scanner in=new Scanner(System.in); String s=new String(); System.out.println("Enter a line:"); s=in.nextLine(); char c; int sp=0,cl=0,cv=0,cs=0,ci=0; for ( int i=0;i<s.length();i++) { c=s.charAt(i); if(c>=65 && c<=90 || c>=97 && c<=122) // condition of A to Z and a to z { cl++; // alphabet's counter incremented if(c=='A' || c=='E' || c=='I' || c=='O' || c=='U'|| c=='a' || c=='e' || c=='i' || c=='o' || c=='u') { cv++; // vowel's counter incremented } } else if(c>=48 && c<=57) { ci++; // digit's counter incremented } else if(c==' ') { sp++; } else { cs++; // special char's counter incremented } } System.out.println("total number of alphabet in this string is "+cl); System.out.println("total number of vowel in this string is "+cv); System.out.println("total number of consonant in this string is "+(cl-cv)); System.out.println("total number of digit in this string is "+ci); System.out.println("total number of space in this string is "+sp); System.out.println("total number of special char in this string is "+cs); } } OUTPUT : :
12654
19/7/2018 02:41:49 pm
***********************************
Reply
MunavvarHushen Durvesh
20/7/2018 09:10:22 am
Any thing you want to know?
Reply
Your comment will be posted after it is approved.
Leave a Reply. |
Hello friends, i am a CSE student and i am going to upload all the programs of various language which might be in your collage practical list or might help you in performing your practicals in lab. Archives
August 2015
Categories |