Class Name CharacterorString
import java.util.*;
import javax.swing.JOptionPane;
import javax.swing.JOptionPane;
public class CharacterorString{
public static void main(String[] Theory)
{
String SentenceContents=JOptionPane.showInputDialog("Enter a string:" );
int VowelCount = 0,ConsonantCount = 0,WordCount = 0,SpaceCount = 0,SpecialCharCount = 0 ;
for (int Bat = 0; Bat < SentenceContents.length(); Bat++)
{
char Vowels = SentenceContents.charAt(Bat );
if ( (Vowels == 'A') || (Vowels == 'a' )
|| (Vowels == 'E') || (Vowels == 'e' )
|| (Vowels == 'I') || (Vowels == 'i' )
|| (Vowels == 'O') || (Vowels == 'o' )
|| (Vowels == 'U') || (Vowels == 'u' ))
VowelCount++;
char Consonants = SentenceContents.charAt(Bat);
if ( (Consonants == 'B') || (Consonants == 'b')
|| (Consonants == 'C') || (Consonants == 'c')
|| (Consonants == 'D') || (Consonants == 'd')
|| (Consonants == 'F') || (Consonants == 'f')
|| (Consonants == 'G') || (Consonants == 'g')
|| (Consonants == 'H') || (Consonants == 'h')
|| (Consonants == 'J') || (Consonants == 'j')
|| (Consonants == 'K') || (Consonants == 'k')
|| (Consonants == 'L') || (Consonants == 'l')
|| (Consonants == 'M') || (Consonants == 'm')
|| (Consonants == 'N') || (Consonants == 'n')
|| (Consonants == 'P') || (Consonants == 'p')
|| (Consonants == 'Q') || (Consonants == 'q')
|| (Consonants == 'R') || (Consonants == 'r')
|| (Consonants == 'S') || (Consonants == 's')
|| (Consonants == 'T') || (Consonants == 't')
|| (Consonants == 'V') || (Consonants == 'v')
|| (Consonants == 'W') || (Consonants == 'w')
|| (Consonants == 'X') || (Consonants == 'x')
|| (Consonants == 'Y') || (Consonants == 'y')
|| (Consonants == 'Z') || (Consonants == 'z') )
ConsonantCount++;
char Spaces = SentenceContents.charAt(Bat);
if ( (Spaces == ' ') )
SpaceCount++;
char SpecialCharacters = SentenceContents.charAt(Bat);
if ( (SpecialCharacters == '!') || (SpecialCharacters == '@' )
|| (SpecialCharacters == '#') || (SpecialCharacters == '$' )
|| (SpecialCharacters == '%') || (SpecialCharacters == '^' )
|| (SpecialCharacters == '&') || (SpecialCharacters == '*' )
|| (SpecialCharacters == '(') || (SpecialCharacters == ')' )
|| (SpecialCharacters == '-') || (SpecialCharacters == '_' )
|| (SpecialCharacters == '+') || (SpecialCharacters == '=' )
|| (SpecialCharacters == ',') || (SpecialCharacters == '<' )
|| (SpecialCharacters == '.') || (SpecialCharacters == '>' )
|| (SpecialCharacters == '?') || (SpecialCharacters == '/' )
|| (SpecialCharacters == '"') || (SpecialCharacters == ';' )
|| (SpecialCharacters == ':') || (SpecialCharacters == '{' )
|| (SpecialCharacters == '[') || (SpecialCharacters == '}' )
|| (SpecialCharacters == ']') || (SpecialCharacters == '~' )
|| (SpecialCharacters == '`') || ((SpecialCharacters == '1' )
|| (SpecialCharacters == '2') || (SpecialCharacters == '3' )
|| (SpecialCharacters == '4') || (SpecialCharacters == '5' )
|| (SpecialCharacters == '6') || (SpecialCharacters == '7' )
|| (SpecialCharacters == '8') || (SpecialCharacters == '9' )
|| (SpecialCharacters == '|') ))
SpecialCharCount++;
String done="";
char Terminate = SentenceContents.charAt(Bat);
if (Terminate == 'd')
JOptionPane.showMessageDialog(null,"the System is terminating");
if ( SentenceContents != null)
{
}
}
JOptionPane.showMessageDialog(null,
"There are " + VowelCount + " vowels in this sentence\n"+
"There are " + ConsonantCount + " consonants in this sentence\n"+
"There are " + SpaceCount + " spaces in this sentence\n" +
"There are " + SpecialCharCount + " special characters in this sentence" );
}
}
No comments:
Post a Comment