/**
 * Arrays:
 * 
 * 1. All elements of an array will have the same type,
 *    say T.
 * 
 * 2.  All elements of an array behave exactly like an
 *   ordinary variable of the array's type T.
 * 
 * 3.  An array is an object.
 * 
 * 4.  The number of elements in an array cannot change
 *   once we've initialized it.
 * 
 * 5.  The type of the array T[] is read as "array of T".
 */ 
public class ArrayDemo {

  /**
   * Display the contents of a on the screen from index 
   * i to index j.  Assume that i <= j.
   * 
   *@param a  the input array
   *@param i  the start index (inclusive)
   *@param j the end index (inclusive)
   */ 
  public static void displayArray(int[] a, int i, int j) {
    for (int k = i; k <= j; k++) {
      System.out.println(a[k]);
    }
  }
  
  /**
   * Return the index of value e in the array a, or -1
   * if that value is not in the array.
   * 
   *@param a the input array
   *@param e the value to search for
   *@return the index of e in array a. -1 if e is not in the array
   */
  public static int findElement(int[] a, int e) {
    int index = -1;
    
    for (int i = 0; i < a.length; i++) {
      if (a[i] == e) {
        index = i;
      }
    }
    return index;
  }
  
  
  /**
   * Return the index of value e in the array a, or -1
   * if that value is not in the array.
   * 
   *@param a the input array
   *@param e the value to search for
   *@return the index of e in array a. -1 if e is not in the array
   */
  public static int findElementV2(int[] a, int e) {
    int index = -1;
    boolean found = false;
    
    for (int i = 0; i < a.length && (!found); i++) {
      if (a[i] == e) {
        index = i;
        found = true;
      }
    }
    return index;
  }

  /**
   * Return the index of value e in the array a, or -1
   * if that value is not in the array.
   *@param a the input array
   *@param the value to search for
   *@return the index of e in array a. -1 if e is not in the array
   */
  public static int findElementV3(int[] a, int e) {
    // exercise: instead of a for loop, use a while loop to write this method
    return 0;
  }
}
