title: Construct an N input OR Gate. An OR Gate returns 0 if all its inputs are 0, otherwise 1 using java
body: <p><strong>Exact question</strong><a href="http://www.practice.geeksforgeeks.org/problem-page.php?pid=1335" rel="nofollow noreferrer">http://www.practice.geeksforgeeks.org/problem-page.php?pid=1335</a></p>
  <blockquote>
  <p>Construct an N input OR Gate. An OR Gate returns 0 if all its inputs
  are 0, otherwise 1.</p>
  </blockquote>
  <ul>
  <li><p>Input:</p>
  </li>
  <li><p>3 //these are testcases</p>
  </li>
  <li><p>2 //these  are number of inputs</p>
  </li>
  <li><p>1 1 //these are inputs</p>
  </li>
  <li><p>3 //these</p>
  </li>
  <li><p>0 0 0</p>
  </li>
  <li><p>4</p>
  </li>
  <li><p>1 1 1 0</p>
  </li>
  <li>
  <blockquote>
  <p>output: 1 //o/p for 1st case</p>
  </blockquote>
  </li>
  <li><p>0 //o/p for second case</p>
  </li>
  <li><p>1</p>
  </li>
  </ul>
  <p><strong>this code is causing run time error</strong></p>
  <blockquote>
  <p>errors such as Scanner java:907,java:1530,java:2160</p>
  </blockquote>
  <pre><code>    class GFG {
        
              static int or(int a[] , int n , int x){
                 for(int i = 0;i&lt;n;i++)
                 {
                     if(x==0)
                        return 0;
                 }
                   return 1;
          }
      public static void main (String[] args) {
          int a[] = new int[100];
          int x= 0;
          Scanner in  =new Scanner(System.in);
          int t = in.nextInt();
          while(t&gt;0){
              int n = in.nextInt();
              for(int i =0; i&lt;n;i++){
                 a[i] = in.nextInt();
                 x =x+(a[i]|a[i+1]);
              }
                 System.out.println(or(a,n,x));
                 t--;
          }
      }
  }
  </code></pre>