0

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);
    }
}
Mad Physicist
  • 107,652
  • 25
  • 181
  • 264

1 Answers1

0

You could use the build in functionality for counting groups.

Example from another question here.

https://stackoverflow.com/a/25441208/2710666

Community
  • 1
  • 1
NMGod
  • 1,937
  • 2
  • 12
  • 11