Question

By using Java public static methods solve following problem Write a method called vowelCount that accepts...

By using Java public static methods solve following problem

Write a method called vowelCount that accepts a String as its only parameter, and returns an array int[5] containing the count of vowels a,e,i,o,u in that String, using ignoreCase. For example, vowelCount("") returns {0,0,0,0,0}, and for the callvowelCount("Bill Iverson") your method returns {0,1,2,1,0} because there is one 'e' and two 'i' vowels (ignore case) and one 'o' with zero counts for 'a' and 'u' vowels.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

import java.util.Scanner;
public class CountingVowel {
   private static Scanner sca;
   private static int [] results;
   static int[] vowelCount(String str)
   {
       int []count=new int[5];
       count[0]=0;
       count[1]=0;
       count[2]=0;
       count[3]=0;
       count[4]=0;
       if(str.length()==0)
       {
           return count;
       }
       else
       {
          
           for(int k=0;k<str.length();k++)
           {
               switch(str.charAt(k))
               {
               case 'a':
                   count[0]++;
                   break;
               case 'e':
                   count[1]++;
                   break;
               case 'i':
                   count[2]++;
                   break;
               case 'o':
                   count[3]++;
                   break;
               case 'u':
                   count[4]++;
                   break;
               }
           }  
           return count;
       }
   }
   public static void main(String str[])
   {
       String input;
       sca = new Scanner(System.in);
       System.out.println("Enter the string");
       input=sca.nextLine();
       results = vowelCount(input);
       System.out.println("{"+results[0]+","+results[1]+","+results[2]+","+results[3]+","+results[4]+"}");
   }

}

Result:

Add a comment
Know the answer?
Add Answer to:
By using Java public static methods solve following problem Write a method called vowelCount that accepts...
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
  • Submit Chapter7.java with four (4) public static methods as follows: A. Write a method called mostCommon...

    Submit Chapter7.java with four (4) public static methods as follows: A. Write a method called mostCommon that accepts an array of integers as its only parameter, and returns the int that occurs most frequently. Break ties by returning the lower value For example, {1,2,2,3,4,4} would return 2 as the most common int. B. Write mostCommon (same as above) that accepts an array of doubles, and returns the double that occurs most frequently. Consider any double values that are within 0.1%...

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • JAVA: Excerpt B.A: Complete the implementation of the following method. The purpose of this method is...

    JAVA: Excerpt B.A: Complete the implementation of the following method. The purpose of this method is to return true if and only if all the elements in the array are x. In other words, all elements in the array are the value x (replace -a- with right answer). public static -a- allSame(int[] nums, int x){ for (int i = 0; i < -a-; i++){ if (nums[i] -a- x){ return -a-; } } return -a- } Excerpt B.B: What is printed...

  • JAVA Array 3. Write a method called noVowels that takes a String as input and returns...

    JAVA Array 3. Write a method called noVowels that takes a String as input and returns true if it doesn't contain any vowels (a, e, i, o, u)

  • You will write three static methods to manipulate an input String in different ways using various...

    You will write three static methods to manipulate an input String in different ways using various String methods. You need to provide the code for each of the three static methods in class StringPlay (requirements for each listed below). You will also change the control statement in the test harness to allow for variations in the sentinel value. You need to modify the loop control condition in Lab09.java so that user inputs of ‘finish’, “FINISH”, “FiniSH”, “fINISH”, etc. will end...

  • In Java write the following array- processing methods into the same application, Lab13.java. Use the main...

    In Java write the following array- processing methods into the same application, Lab13.java. Use the main method in this application to test your methods. 1) Write the void method, shiftLeft, which accepts an array of int and changes the elements of this array so that the index of each element is now less by one and the last element of the array is now zero. For example, if the parameter array is {7, 3, 2, 9, 5}, then when this...

  • In java, write method, shuffle, which accepts an array of int, creates a copy of the...

    In java, write method, shuffle, which accepts an array of int, creates a copy of the formal parameter, shuffles the copy, then returns the copied, shuffled array, leaving the formal parameter unchanged. Shuffling is a process of swapping each element of array with another element randomly chosen from the array. For testing the shuffle method have main call shuffle, repeatedly having it shuffle its previously returned array until the returned (shuffled) array is identical (equal) to the original array that...

  • pls help java ASAP!!!!!!! Topic String Tokenizer Static Methods Static Variables Primitive Arrays Description Enhance the...

    pls help java ASAP!!!!!!! Topic String Tokenizer Static Methods Static Variables Primitive Arrays Description Enhance the last assignment by providing the following additional features: (The additional features are listed in bold below) Class Statistics In the class Statistics, create the following static methods (in addition to the instance methods already provided). • A public static method for computing sorted data. • A public static method for computing min value. • A public static method for computing max value. • A...

  • AddressHelper Written in - JAVA Write a class called AddressHelper that provides the following static methods...

    AddressHelper Written in - JAVA Write a class called AddressHelper that provides the following static methods to help with      formatting and printing addresses: addMrPrefix() Returns the string “Mr. “ concatenated with the String argument. addMsPrefix() Returns the string “Ms. “ concatenated with the String argument. determineStateAbbreviation() Takes a String argument containing a state. Returns the corresponding abbreviation as String using the following lookup table: New York NY New Jersey NJ California CS Florida FL other -- determineZipcode() Takes a String...

  • 4. [Tests basic knowledge of recursion] Write a recursive static Java method that accepts an array...

    4. [Tests basic knowledge of recursion] Write a recursive static Java method that accepts an array arr of integers argument returns a list of all permutations of these integers. (A permutation of a sequence of integers is a re-arrangement of the integers. For example, one permutation of 1, 3, 4, 8, 2 is 3, 1, 2, 8, 4.) For this problem, you may assume that the input array contains no duplicate entries. Your method should return an ArrayList of int...

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
ADVERTISEMENT