title: how to create multiple scanner elements in java
body: <p>I have a main function in which I use scanner to read an integer from console.
  Inside this main function, we can access another function which also uses scanner to read an integer. So, the program swings between these two functions many times. But, Java.util.scanner throws an exception. Is there any way to overcome this?</p>
  
  <pre><code>import java.util.Scanner;
  
  public class dummy {
  
      public static void main(String[] args) {
  
          int buy;  
  
          Scanner sc = new Scanner(System.in);
          buy = sc.nextInt();
          user = dummy2();
          sc.close();
      }
  
      static boolean dummy2(){
  
          Scanner sc1 = new Scanner(System.in);
          sc1.close();
      }
  }
  </code></pre>