Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Java by ciaracallanan ( 5 years ago )
/**
 * This program prompts the user for a string, then gives diadnostics of it.
 * 
 */
import java.util.Scanner;
public class TextAnalysis
{
    public static void main(String[] args)
    {
        /*
         * Have the user enter a string
         * Print out how many of the following:
         * total characters
         * exclamation marks
         * vowel count
         * spaces
         * word count
         */
        Scanner in = new Scanner(System.in);
        System.out.println("Please enter a sentence and I will give you the diagnostics!");
        String sentence = in.nextLine();
        int charCount = 0;
        int exclamCount = 0;
        int vowelCount = 0;
        int spaceCount = 0;
        int wordCount = 0;
        for(int i = 0; i < sentence.length(); i++)
        {
            if(sentence.charAt(i) == '!')
            {
                exclamCount++;
            }
            else if(sentence.charAt(i) == 'a'||sentence.charAt(i) == 'e'||sentence.charAt(i) == 'i'||sentence.charAt(i) == 'o'||sentence.charAt(i) == 'u')
            {
                vowelCount++;
            }
            else if(sentence.charAt(i) == ' ')
            {
                spaceCount++;
            }
            else if(i>0 && sentence.charAt(i)!=' ')
            {
                wordCount++;
            }
        }
            System.out.println("The total number of characters is: " + sentence.length());
            System.out.println("The number of exclamation marks is: " + exclamCount);
            System.out.println("The total number of vowels is: " + vowelCount);
            System.out.println("The total number of spaces is: " + spaceCount);
            System.out.println("The word count is: " + wordCount);
            System.out.println("Thank you for playing!");
   }
}

 

Revise this Paste

Your Name: Code Language: