Do the following:
- Write and test a function that takes an array of doubles and
returns the average of the values in the array
- Write and test a function that takes an array of doubles and
returns number of values in the array that are above the average of
the values in the array
- Write and test a function that takes an array of Strings and
returns number of values in the array that start with an uppercase
letter. You can use these built in functions
---String Class: char charAt(int index) Returns the char value at
the specified index.
---Character Class: static boolean isUpperCase(char ch) Determines
if the specified character is an uppercase character
public class StringTest {
public static double findAvg(double arr[]) {
double sum = 0;
for(double x: arr) {
sum += x;
}
return sum/arr.length;
}
public static int aboveAvg(double arr[]) {
double avg = findAvg(arr);
int count = 0;
for(double x: arr) {
if(x > avg) {
count++;
}
}
return count;
}
public static int uppercaseStrings(String arr[]) {
int count = 0;
for(String x: arr) {
if(Character.isUpperCase(x.charAt(0))) {
count++;
}
}
return count;
}
public static void main(String[] args) {
System.out.println(findAvg(new double[] {2.5, 2.5, 5})); // 3.3
System.out.println(aboveAvg(new double[] {2.5, 2.5, 5})); // 1
System.out.println(uppercaseStrings(new String[] {"Tom", "jane", "maria"})); // 1
}
}
Please upvote, as i have given the exact answer as asked in question. Still in case of any concerns in code, let me know in comments. Thanks!
Do the following: - Write and test a function that takes an array of doubles and...
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...
Develop a set of static methods in a class called Array Tools that perform the functions below, and overload the methods for the specified types: Description Returns the minimum value stored in an array. Array Tools Method char minimum char array[]) int minimum( int array[] ) double minimum double arrayll ) char maximum char array() ) int maximum( int array[] ) double maximum( double array[] ) Returns the maximum value stored in an array. int minimumAt( char array()) int minimumAt(...
public static int countCharacter(String str, char c) { // This recursive method takes a String and a char as parameters and // returns the number of times the char appears in the String. You may // use the function charAt(int i) described below to test if a single // character of the input String matches the input char. // For example, countCharacter(“bobbie”, ‘b’) would return back 3, while // countCharacter(“xyzzy”, ‘y’) would return back 2. // Must be a RECURSIVE...
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.
write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy. The function should be passed 2 parameters, as illustrated in the prototype below. int pow_xy(int *xptr, int y); Assuming that xptr contains the address of variable x, pow_xy should compute x to the y power, and store the result as the new value of x. The function should also return the result. Do not use the built-in C function pow. For the remaining problems,...
containsSubSequence takes two Strings as input and returns a boolean: Returns true if the first input string contains all the characters of the second input string, in order, but not necessarily consecutively. > HW2.containsSubSequence("abracadabra", "abcd") true > HW2.containsSubSequence("abracadabra", "abdc") false you must not use either break or continue in your code. You are allowed to use the following methods from the Java API: class String length charAt class StringBuilder length charAt append toString class Character any method I write something...
Write a public static method named getMaxOf2Ints that takes in 2 int arguments and returns the Maximum of the 2 values Write a public static method named getMinOf2Ints that takes in 2 int arguments and returns the Minimum of the 2 values Write apublic static method named getMaxOf3Ints that takes in 3 int arguments and returns the Maximum of the 3 values Write a public static method named getMedianOf3Ints that takes in 3 int arguments and returns the Median Value...
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.
u also need to store the letters' ASCII number in the freq
array
4. [8] Write a C function with prototype · void letter_freq(const char word[], int freq []); This function computes the number of appearances of each letter in the string word and stores them in array freq of size 26. The letters are the 26 letters of the Latin alphabet whose ASCII values are in the range 97-122 for the lower case letters, and in the range 65-90...
1. Write a function named findTarget that takes three parameters: numbers, an array of integers - size, an integer representing the size of array target, a number The function returns true if the target is inside array and false otherwise 2. Write a function minValue that takes two parameters: myArray, an array of doubles size, an integer representing the size of array The function returns the smallest value in the array 3. Write a function fillAndFind that takes two parameters:...