title: how to see if a certain value is in an array?
body: <p>I am a beginer.</p>
  
  <p>I tried to find if a certain value is in an array. i.e to see if mnth is in month1[]. </p>
  
  <p>Why is this code showing a runtime exception: </p>
  
  <pre><code>   ArrayIndexOutOfBoundsException.
  </code></pre>
  
  <p>How to avoid  this exception ? </p>
  
  <p>how to  find if a certain value is in an array? with the for loop i tried to do that. </p>
  
  <p>please tell me where i am wrong. </p>
  
  <p>Thanks in advance. </p>
  
  <pre><code>import java.util.*;
  import java.lang.*;
  import java.io.*;
  
  /* Name of the class has to be "Main" only if the class is public. */
  class Ideone {
      public static void main(String[] args) throws java.lang.Exception {
              Scanner scanner = new Scanner(System.in);
          String dt = scanner.nextLine();
          String[] date = new String[3];
          date = dt.split("/");
              System.out.println(date[0]);
              int yr = Integer.valueOf(date[0]);
          int mnth = Integer.valueOf(date[1]);
              int day = Integer.valueOf(date[2]);
              int[] month1 = { 1, 3, 5, 7, 8, 10, 12 };
              int i;
              boolean x=false;
          for (i = 0; mnth != month1[i]&amp;&amp;i&lt;=2&amp;&amp;x==false; i++) {
              x = yr % 2 == 0 &amp;&amp; mnth == 2 ? day &lt;= 29: mnth == 2 ? day &lt;= 28 : mnth == month[i] ? day &lt;= 31 : day &lt;= 30;
                  }
          System.out.println("" + x);
  
      }
  }
  </code></pre>