import javax.swing.JOptionPane;
public class asgn3{
public static void main( String[] args )
{
String sentence = JOptionPane.showInputDialog(null,
"Enter a sentence");
boolean first_letter = true;
char this_char;
int upper = 0;
int lower = 0;
int space = 0;
int other = 0;
int counter = 0;
int total = sentence.length();//declared all the variables
while (counter < total) {
this_char = sentence.charAt(counter);
if (first_letter == true) { // capitalize all first letter of each word
if (this_char >= 97 && this_char <= 122) {
this_char -= 32; // convert to uppercase
System.out.print (this_char);
upper++; //bump the count of upper case characters
first_letter == false;// reset the flag so next loop won't look at first letter.
}
}
else { //
if (this_char >= 65 && this_char <= 122) {// if this is an upper case letter
this_char += 32;// convert it to lower case.
lower++; // update count of lower case letters.
}
// print out the letter.
else {
if (this_char == 32) // if this is a blank
// set the flag that tells the loop to capitalize the first letter
space++;// update count of blanks
}
// print the character withut a line return.
counter++;
}
System.out.println("Total: " + total);
System.out.println("Upper: " + upper);
System.out.println("Lower: " + lower);
System.out.println("Space: " + space);
System.out.println("Other: " + other);
System.out.println("Total: " + total);
} // end main
} // end of program