Answer to Question #289294 in Java | JSP | JSF for Kev

Question #289294

We've had enough about numbers, so why don’t we try evaluating characters now?


If you know how to identify what the vowel letters are, and you know how to count up to 5, then you’re good to go!




Instructions:


Using a do…while() loop, continuously scan for characters (one per line) and print it out afterwards. Remember to place a space before the character's placeholder when scanning so that the newline characters will be ignored and the correct values will be scanned.

The loop shall terminate due to either of the following reasons:

The inputted character is a vowel

The number of inputted characters has already reached 5.

For all of the test cases, it is guaranteed that if the number of inputted characters is less than 5, then there must be a vowel from among the inputted characters. Also, it is guaranteed that all the characters are in lowercase.


It must also be guaranteed that if the number of inputted characters is less than 5, then there must be a vowel from among the inputted characters.


1
Expert's answer
2022-01-21T01:46:09-0500
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String line;
        int counter = 0;
        do {
            line = in.nextLine();
            counter++;
        } while (counter < 5 && line.charAt(0) != 'a' && line.charAt(0) != 'o' && line.charAt(0) != 'e'
                && line.charAt(0) != 'i' && line.charAt(0) != 'u');
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog