Vowel count Consonant Count Space Count and Digit count using Java
Java Programming Language String in java (Article) String in java (Program)
29
Given Input:
Enter a String: My Name is Atique123
Expected Output:
here is your length Of String: 20
Here is your vowel count: 7
Here is your consonant count: 7
here is your space count: 3
here is your digit count: 3
Program:
import java.util.*;
class VowelCount{
public static void main(String args[]){
String userString;
int loopVariable, spaceCount = 0, vowelCount = 0, consonantCount = 0, digitCount = 0, lengthOfString;
Scanner sc = new Scanner(System.in);
System.out.print("Enter a String: ");
userString = sc.nextLine();
lengthOfString = userString.length();
for(loopVariable = 0; loopVariable < lengthOfString; loopVariable++)
{
char presentCharacter = userString.charAt(loopVariable);
if( presentCharacter == 'a' || presentCharacter == 'e' || presentCharacter == 'i' ||
presentCharacter == 'o' || presentCharacter == 'u' || presentCharacter == 'A' || presentCharacter == 'E'||
presentCharacter == 'I' || presentCharacter == 'O' || presentCharacter == 'U')
{
vowelCount = vowelCount + 1;
}
else if(presentCharacter == ' ')
{
spaceCount++;
}
else if(presentCharacter > '0' && presentCharacter < '9'){
digitCount = digitCount + 1;
}
else
{
consonantCount = consonantCount + 1;
}
}
System.out.println("here is your length Of String: "+lengthOfString);
System.out.println("Here is your vowel count: "+vowelCount);
System.out.println("Here is your consonant count: "+consonantCount);
System.out.println("here is your space count: "+spaceCount);
System.out.println("here is your digit count: "+digitCount);
}
}
Output:
Enter a String: My Name is Atique123
here is your length Of String: 20
Here is your vowel count: 7
Here is your consonant count: 7
here is your space count: 3
here is your digit count: 3
Press any key to continue . . .
This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.
here is your length Of String: 20 Here is your vowel count: 7 Here is your consonant count: 7 here is your space count: 3 here is your digit count: 3
Program:
import java.util.*; class VowelCount{ public static void main(String args[]){ String userString; int loopVariable, spaceCount = 0, vowelCount = 0, consonantCount = 0, digitCount = 0, lengthOfString; Scanner sc = new Scanner(System.in); System.out.print("Enter a String: "); userString = sc.nextLine(); lengthOfString = userString.length(); for(loopVariable = 0; loopVariable < lengthOfString; loopVariable++) { char presentCharacter = userString.charAt(loopVariable); if( presentCharacter == 'a' || presentCharacter == 'e' || presentCharacter == 'i' || presentCharacter == 'o' || presentCharacter == 'u' || presentCharacter == 'A' || presentCharacter == 'E'|| presentCharacter == 'I' || presentCharacter == 'O' || presentCharacter == 'U') { vowelCount = vowelCount + 1; } else if(presentCharacter == ' ') { spaceCount++; } else if(presentCharacter > '0' && presentCharacter < '9'){ digitCount = digitCount + 1; } else { consonantCount = consonantCount + 1; } } System.out.println("here is your length Of String: "+lengthOfString); System.out.println("Here is your vowel count: "+vowelCount); System.out.println("Here is your consonant count: "+consonantCount); System.out.println("here is your space count: "+spaceCount); System.out.println("here is your digit count: "+digitCount); } }
Output:
Enter a String: My Name is Atique123 here is your length Of String: 20 Here is your vowel count: 7 Here is your consonant count: 7 here is your space count: 3 here is your digit count: 3 Press any key to continue . . .
This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.