title: Unable to read input from static block using scanner class
body: <p>i want to read the data from the user in the static block and need to check some condition there but when i am trying to call nextInt() it causes some error  </p>
  
  <pre><code>public class Test {
      static int B,H;
      static{
          Scanner s=new Scanner(System.in);
          B=H=0;
          B=s.nextInt();
          H=s.nextInt();
          s.close();
      }
  }
  </code></pre>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.ExceptionInInitializerError</p>
    
    <p>Caused by: java.util.NoSuchElementException
                at java.util.Scanner.throwFor(Scanner.java:862)
                at java.util.Scanner.next(Scanner.java:1485)
                at java.util.Scanner.nextInt(Scanner.java:2117)
                at java.util.Scanner.nextInt(Scanner.java:2076)
                at Solution.initialise(Solution.java:21)
                at Solution.(Solution.java:15)</p>
  </blockquote>