Question: JAVA I am new to methods. This is the assignement, and this is the original code that you are to change to using methods. import
JAVA
I am new to methods. This is the assignement, and this is the original code that you are to change to using methods.
import java.util.Scanner;
public class Vowels { public static void main(String[] args) { Scanner input = new Scanner(System.in); int vowelCount; String sentence = ""; System.out.println("Welcome! Give me a sentence and I will count its vowels. "); do { System.out.print("Please enter a sentence or q to quit: "); sentence = input.nextLine(); vowelCount = 0; if (!sentence.equalsIgnoreCase("q")) { for(int i = 0; i Write a method with the following signature public static int countVowels (string str) The method returns a count of the vowel letters in the string parameter that are vowels (A, E, I, O, U, a, e, i, o, u) Hint: You've done this same thing on your previous assignment, just not with a method. For this assignment we are going to "outsource" the work of counting vowels to a method named countVowels. Copy and paste the starter code inside the 0of a class named Vowels either above or below the main method: public static int countVowels (string str) //add the code for your method here Cut and paste the for loop from main and place it inside the of the method. . Then, in main, call the method to replace the for loop Verify that your new version of the program still works identically to Assignment 14.3 Welcome! Give me a sentence and I will count its vowels. Please enter a sentence or q to quit: Power to the people! There are 7 vowels in your sentence Please enter a sentence or q to quit: Chillax! There are 2 vowels in your sentence. Please enter a sentence or q to quit: Animals are friends not food. There are 10 vowels in your sentence. Please enter a sentence or q to quit: q Goodbye
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
