I'm curious on how to build an array (in Java) that tallies how large a group is (consecutive elements with the same value) and prints it through a seperate runner file. So far, this is my code. I've got everything down except for the getNumGroupsOfSize
method, which does the counting:
import static java.lang.System.*;
import java.util.Arrays;
import java.util.Scanner;
public class ArrayStats
{
int[] numArray;
public ArrayStats(int[]array)
{
setArray(int[]array);
}
public void setArray(int[]array)
{
numArray=array;
}
public int getNumGroupsOfSize(int size)
{
int cnt=0;
for (int x=0; x<=size.length; x++)
{
do
{
count++;
}
while (size[x]=size[x+1]);
return cnt;
}
}
public String toString()
{
return ""+Arrays.toString(array);
}
}