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 Wkimball ( 5 years ago )
/**
 * This program prompts the user for a string, then gives diagnostics about it
 * @wkimball
 * @4/8/21
 */
import java.util.Scanner; 
public class TextAnalysis
{
    public static void main(String[] args)
    {
        /*
         * Have user enter a string
         * 
         * Print out how many instances of the following occur
         * 
         * total characters
         * exclamation marks 
         * vowel count
         * spaces
         * wordcount
         */
        
       System.out.println("Enter a sentence for a text analysis"); 
       String sentence = in.nextLine(); 
       
       int totalChar = 0;
       int exclamCount = 0; 
       int vowelCount = 0;
       int spaceCount = 0;  
       int wordCount = 0; 
       
       int cha = sentence.length(); 
       for(int i = 0; i < sentence.length(); i++) 
       {
           if(sentence.substring(i, i + 1).equals("!")) 
            {
              exclamCount ++; 
            }
       }
       System.out.println("The amount of exclamation marks is " + exclamCount); 
       for(int i = 0; i < sentence.length(); i++) 
       {
           if(sentence.substring(i, i + 1).equals(" ")) 
           {
              spaceCount ++; 
           }  
       }
       System.out.println("The amount of spaces is " + spaceCount); 
       for(int i = 0; i < sentence.length(); i++) 
       {
           if(sentence.charAt(i) == 'e' ||sentence.charAt(i) == 'o' ||sentence.charAt(i) == 'i' ||sentence.charAt(i) == 'u' ||sentence.charAt(i) == 'a') 
           {
              vowelCount ++; 
           }  
       }
       System.out.println("The amount of vowels is " + vowelCount); 
       for(int i = 0; i < sentence.length(); i ++) 
       {
           {
               totalChar ++; 
           }
       }
       System.out.println("The amount of characters is " + totalChar); 
       char ch[] = new char[sentence.length()];
       for(int i = 0; i < sentence.length(); i ++) 
       {
           ch[i]= sentence.charAt(i);  
           if( ((i>0)&&(ch[i]!=' ')&&(ch[i-1]==' ')) || ((ch[0]!=' ')&&(i==0)) )  
           {
              wordCount ++; 
           }
       }
       System.out.println("The amount of words is " + wordCount); 
}
}

 

Revise this Paste

Your Name: Code Language: