Question: avgWordLength ( ) Method Write a method called avgWordLength ( ) that takes in an Array of String, and returns the average length of the

avgWordLength() Method
Write a method called avgWordLength() that takes in an Array of String, and returns the average length of the Strings in the Array. Remember, that an average is of type double.
Your goal is to do the following:
Traverse the Array .
Find the average length of all of the words that are part of words Array.
Return the average length.
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class CodingQuestion {
// Write your static method here
/***** DO NOT CHANGE THE CODE BELOW THIS LINE *****/
public static void main(String[] args){
Scanner in = new Scanner(System.in);
String[] words = new String[5];
for (int i =0; i <5; i++){
words[i]= in.nextLine();
}
double avgLength = avgWordLength(words);
System.out.println("The average word length is "+ avgLength +".");
}// end of main()
}
Expected STDOUT
The average word length is 7.0.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!