Advertisement
advictoriam

Untitled

Jan 17th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. public class ArrayOps
  2. {
  3.    /**
  4.       This method goes through the array of integers identified by
  5.       the first parameter, while counting the number of occurrences
  6.       of the second parameter, a single integer, within the array.
  7.       @param theArray, an array of integers
  8.       @param theChar, an integer whose occurrences within the array
  9.          need to be counted
  10.       @ return, the count of the occurrences of the integer represented
  11.       by the second parameter in the array of integers.
  12.    */
  13.    public static int countOccurs(int[] theArray, int theInt)
  14.    {
  15.       int count = 0;
  16.  
  17.       for(int a : theArray)
  18.       {
  19.          if(a == theInt){count++;}
  20.       }
  21.       return count;
  22.    }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement