advictoriam

Untitled

Jan 17th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. public class ArrayOps
  2. {
  3.    /**
  4.       This method performs a linear search on the array identified by
  5.       the first parameter, while looking for the value indicated by
  6.       the second parameter.
  7.       @param values, an array of integers
  8.       @param valueToFind, an integer to look for in the array values
  9.       @ return, the index (subscript) of the array where the value
  10.             was found OR the length of the array if it was not found.
  11.    */
  12.    public static int findValue(int values[], int valueToFind)
  13.    {
  14.       for(int i = 0; i < values.length; i++)
  15.       {
  16.          if(values[i] == valueToFind){return i;}
  17.       }
  18.       return values.length;
  19.    }
  20. }
Add Comment
Please, Sign In to add comment