Question: Homework 1 Java Write a method longestPrefix that finds the longest prefix of an array of numbers such that the average of that prefix is

Homework 1 Java

Write a method longestPrefix that finds the longest prefix of an array of numbers such that the average of that prefix is less than an upper bound. Specifically, the method takes an array of floats x and a float upperBound and returns the greatest index i such that elements 0 through i of x have an average less than the upper bound or returns -1 if there is no such index. See LongestPrefix.java for example test cases.

Examples,

Homework 1 Java Write a method longestPrefix that finds the longest prefix

public static void main(String[l args) [ System.out.println ("LongestPrefix") float input -[0, 1, 2, 3, 4 test( testNum: 1, input, upperBound: 1.2f, expected: 2): float input -[0, 1, 2, 3, 4 test( testNum: 2, input, upperBound: 1.8f, expected: 3): float input - [4, 3, 2, 1, 0 test( testNum: 3, input, upperBound: 1.2f, expected: -1): float input - [4, 3, 2, 1, 0, 0, 0, 0, 0: test( testNum: 4, input, upperBound: 1.2f, expected: 8): float input -[4, 3, 2, 1, 0, 0, 0, 0, 1: test testNum: 5, input, upperBound: 1.2f, expected: -1): /takes an array of floats x and an upper bound //returns the greatest index i such that elements 0 through i of x have an average less than the upper bound 1or returns -1 if there is no such index public static int longestPrefix(float x[l, float upperBound) [...)

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 Databases Questions!