The RunFinder class has a constructor that takes an int
Array of values and stores them. It also has two accessor methods:
A toString()
method which returns a String
version of the array in the format:
int[value0,value1,value2,...,lastValue]
An identifyRuns()
method which analyzes the values in the array and returns a string with sequential runs of any value surrounded by parentheses.
Sample interaction:
int[] values = {5,1,3,3,6,4,2,6,5,5,5,5,4,2,2,4,3,2,1,3};
RunFinder rf = new RunFinder(values);
System.out.println(rf);
produces: int[5,1,3,3,6,4,2,6,5,5,5,5,4,2,2,4,3,2,1,3]
System.out.println(rf.identifyRuns());
produces: 51(33)6426(5555)4(22)43213
The LongRunFinder
is similar, but includes a third method, identifyLongestRun()
, which identifies the single longest run in the array. For that same data set:
System.out.println(rf.identifyLongestRun());
produces: 51336426(5555)42243213
If there is more than a single longest run, the method can identify either one of the longest runs as being the longest.