Question: Java array. Please keep it basic and simple. public class PQ06 { /** * 1. Write the method maxEnd3() *
Java array. Please keep it basic and simple.
public class PQ06
{
/**
* 1. Write the method maxEnd3()
*
* You are given an array of int of any length.
* Your method should figure out which is the
* larger of the first and last elements in the
* array, and then new array of length 3,
* with every element set to that value. Return
* the new array. Do not change your original
* array.
*
* Some examples:
* maxEnd3({1, 2, 3}) returns {3, 3, 3}
* maxEnd3({11, 5, 9}) returns {11, 11, 11}
* maxEnd3({2, 11, 3}) returns {3, 3, 3}.
*
* @param nums an array of int (any length)
* @return an array (length 3) containing the maximum element.
*/
// WRITE THE METHOD maxEnd3() HERE
/**
* 2. Write the method averageOdds()
*
* Start with a positive int array of named nums. Return the
* average of all the odd numbers in the array.
* A number (n) is odd if n % 2 == 1. If there are no
* odd numbers in the array, return -1.
*
* Some examples:
* averageOdds([1, 2, 3]) returns 2.0
* averageOdds([2, 4]) returns -1.0
* averageOdds([2, 3, 4]) returns 3.0
*
* @param nums an array of int (any length)
* @return the average of the odd numbers in the array.
*/
// WRITE THE METHOD averageOdds() HERE
}
Step by Step Solution
There are 3 Steps involved in it
Program plan Begin by declaring a Java class named Main Inside the class define the main method which serves as the entry point of the program Define three sample integer arrays arr1 arr2 and arr3 wit... View full answer
Get step-by-step solutions from verified subject matter experts
