Write a method named avgLength which takes an array of Strings as an input parameter and returns a double. The method should calculate and return the average length of all the strings in the array (in java langauge)
Method Implementation
//This method will find the average length of all strings in the string array
private static double avgLength(String[] str) {
double sum=0.0,avg=0.0;
for(int i=0;i<str.length;i++)
{
//Calculating the sum of length of all strings in the array
sum+=str[i].length();
}
//Calculating the average
return sum/str.length;
}
_________________
CalAverageLengthOfArray.java(Complete Program)
public class CalAverageLengthOfArray {
public static void main(String[] args) {
String str[] = {
"Hello",
"Sachin",
"Tendulkar",
"Ricky",
"Pointing",
"Helen"
};
double average = avgLength(str);
System.out.printf("The average length of all the strings : %.2f",
average);
}
//This method will find the average length of all strings in the
string array
private static double avgLength(String[] str) {
double sum = 0.0, avg = 0.0;
for (int i = 0; i < str.length; i++) {
//Calculating the sum of length of all strings in the array
sum += str[i].length();
}
//Calculating the average
return sum / str.length;
}
}
__________________
Output:
The average length of all the strings : 6.33
_____________Could you rate me well.Plz .Thank You
Write a method named avgLength which takes an array of Strings as an input parameter and...
Python: Write a function named "sort_by_length" that takes a list/array of strings as a parameter and sorts the strings by their length
JavaScript Write a function named "sort_by_length" that takes a list/array of strings as a parameter and sorts the strings by their length
1.Write code for a Java method, printArray, that takes an int array as parameter and prints it out, one element per line. public static void printArray (int[] values){ Methods that do NOT return a result have “void” as return type. Notice how an array parameter type is passed, int [] }// end printArray 2.Write code for a Java method that takes in as input parameter an integer number, say num, and returns a double array of size num with all...
Write a static method that takes an array of Strings and returns a double. Determine the average number of characters for the Strings assigned to the array. Return the average.
Write a method markLength4 that takes an array of Strings as a parameter and that places a string of four asterisks "****" in front of every string of length 4.
JAVA 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a parameter. This method calculates and returns the largest even number in the list. If there are no even numbers in the array, the method should return 0. You can assume that the array is not empty. For example: Test Result int[] values = {1, 4, 5, 9}; System.out.println(getMaxEven(values)); 4 System.out.println(getMaxEven(new int[]{1, 3, 5, 9})); 0 public static int --------------------------------------------------------------------------------- 2. Write a static method...
/** * Write a method named outOfOrder that takes as a parameter an array of double and returns a value of type int. * This method will test the array for being out of order, meaning that the array violates the conditions: * array[0] <= arrayValues[0] <= arrayValues[2] <=... * * The method returns -1 if the elemnts are not out of order; otherwise , it returns the index of the first element of the array that is out of...
Write a method called averageVowels that takes an ArrayList of strings as a parameter and returns the average number of vowel characters (a, e, i, o, u) in all Strings in the list. If your method is passed an empty ArrayList, it should return 0.0.
In JAVA: Write the definition/implementation of a method named MyMethod that takes 2 strings and return the total length of the 2 strings. For example, if the method is called with strings “hello” and “there”, the method returns 10. Show how you would call this method (I don't need the full program, just a proper statement to call the method).
Write a function that takes an array of C-strings as a parameter and the number of elements currently stored in the array, and returns a single C-string pointer that is the concatenation of all C-strings in the array. Note: The function must take 2 parameters and return "char *". Any other ways will cause some deduction of points.