Question

String data and string manipulations are a major capability in any type of data processing. Character...

String data and string manipulations are a major capability in any type of data processing. Character arrays are rather limited compared to String data types.

This application will:

1. Allow the user to enter a string (multiple words including blanks)

2. Determine the number of vowels (a, e, i, o, u) and non vowels.a. Total number of Individual a’s, e’s, i’s, o’s, u’sb. Uppercase vowels count the same as lowercase vowels (i.e. “A” is the same as “a”)c. Any other characters count as “non vowels”

3. Allow the user to run this application as many times as they wish

Output example:

Enter a string of text: Space the final frontier

There are 24 characters in "Space the final frontier"

"Space the final frontier" has:

2 A's

3 E's

2 I's

1 O's

0 U's

16 non vowels

Enter Another string (Y or N):

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class CountVowels {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String line, choice;
        char ch;
        while (true) {
            System.out.print("Enter a string of text: ");
            line = in.nextLine();
            System.out.println("There are " + line.length() + " characters in \"" + line + "\"");
            System.out.println("\"" + line + "\" has:");
            int a = 0, e = 0, i = 0, o = 0, u = 0;
            for (int j = 0; j < line.length(); j++) {
                ch = Character.toLowerCase(line.charAt(j));
                if (ch == 'a') a++;
                else if (ch == 'e') e++;
                else if (ch == 'i') i++;
                else if (ch == 'o') o++;
                else if (ch == 'u') u++;
            }
            System.out.println(a + " A's");
            System.out.println(e + " E's");
            System.out.println(i + " I's");
            System.out.println(o + " O's");
            System.out.println(u + " U's");
            System.out.println((line.length() - (a+e+i+o+u)) + " non vowels");
            System.out.print("Enter Another string (Y or N): ");
            choice = in.nextLine();
            if (choice.equalsIgnoreCase("n")) {
                break;
            }
        }
    }

}
Add a comment
Know the answer?
Add Answer to:
String data and string manipulations are a major capability in any type of data processing. Character...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a program that performs the following operations: 1. Prompt for and accept a string of...

    Create a program that performs the following operations: 1. Prompt for and accept a string of up to 80 characters from the user. • The memory buffer for this string is created by: buffer: .space 80 #create space for string input The syscall to place input into the buffer looks like: li $v0,8 # code for syscall read_string la $a0, buffer #tell syscall where the buffer is li $a1, 80 # tell syscall how big the buffer is syscall 2....

  • Part 2: Processing Strings (Individual work) Processing user-entered data to follow a specific format is a...

    Part 2: Processing Strings (Individual work) Processing user-entered data to follow a specific format is a common task. Often this involves using string functions to manipulate a set of input strings. Create a MATLAB script named namephone.m and place these lines of code at the beginning: name  = input('Enter your first and last name: ','s'); phone = input('Enter your area code and phone number: ','s'); Tasks Here are useful string functions:  length, strcat, strtrim, lower, upper, strcmp, findstr, strrep As you work...

  • Capitalization JAVA In this program, you will read a file line-by-line. For each line of data...

    Capitalization JAVA In this program, you will read a file line-by-line. For each line of data (a string), you will process the words (or tokens) of that line one at a time. Your program will capitalize each word and print them to the screen separated by a single space. You will then print a single linefeed (i.e., newline character) after processing each line – thus your program will maintain the same line breaks as the input file. Your program should...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT