Answered step by step
Verified Expert Solution
Question
1 Approved Answer
STARTER CODE: public class PA2b { /** * Error to supply if input is not positive */ public static final String ERR_VALUES = Number of
STARTER CODE:
public class PA2b { | |
/** | |
* Error to supply if input is not positive | |
*/ | |
public static final String ERR_VALUES = "Number of values must be positive."; | |
/** | |
* Returns true if the supplied array has a | |
* sequence of k consecutive values | |
* | |
* @param values input array | |
* @param k sequence length for which to search | |
* @return true if values has a consecutive sequence of at least k | |
*/ | |
public static boolean hasConsecutive(int[] values, int k) { | |
return false; | |
} | |
/** | |
* Returns the length of the longest | |
* consecutive sequence in the supplied | |
* array | |
* | |
* @param values input array | |
* @return length of the longest consecutive value sequence in values | |
*/ | |
public static int maxConsecutive(int[] values) { | |
// Hint: hasConsecutive could | |
// be very useful here | |
return 0; | |
} | |
/** | |
* Inputs an array of numbers | |
* and outputs the longest consecutive | |
* sequence of values | |
* | |
* @param args command-line arguments, ignored | |
*/ | |
public static void main(String[] args) { | |
// Hint: useful methods and constants here | |
// - maxConsecutive | |
// - ERR_VALUES | |
} | |
} |
please make sure has consecutive produces the right true or false and please make sure program does not have java.lang.NegativeArraySizeException: -1
Problem b (PA2b.java) You are to write a program that inputs an array of integers and then outputs the length of the longest sequence of repeating values. For example... Enter the number of values: 7 Enter the values: 3 3 5 5 5 5 4 The maximum length of consecutive values is 4. Enter the number of values: 9 Enter the values: 3 4 5 5 6 5 5 4 5 The maximum length of consecutive values is 2. The program will first prompt the user for integers to store an in array. This array will then be passed to a method in order to ascertain the longest repeating sequence. Before attempting the full program, you will first implement a method that checks whether a sequence of a certain length exists in an array. You should complete this method first, then proceed to the maximum length method, and then finally the main methodStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started