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 efinn ( 5 years ago )
/**
* Have the user enter a String
* 
* Print out how many instances of the following occur
* 
* total characters
* exclamation marks
* vowel count
* spaces
* word count. 

 *
 * @efinn
 * @4/8/21
 */

import java.util.Scanner; 

public class TextAnalysis
{
public static void main(String [] args)
{
Scanner in= new Scanner(System.in);
System.out.println("Enter a sentence for a full analysis");
String sentence = in.nextLine();
        
int totalChar = 0;
int exclamCount = 0;
int vowelCount = 0;
int spaceCount = 0;
int wordCount = 0;
        
System.out.println("Enter a sentence for a full 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: