How to fix NoSuchElementExeption in Java : <p>I've made a simple game with 2 classes. It uses a scanner and when I try it it says java.util.NoSuchElementExeption. It also says the errors are on row 19 in RNGlog and 24 in RNG. Please help</p>

<p>First class: RNG</p>

<pre><code>public class RNG {

public static void main(String[] args) {

    RNGlog log = new RNGlog();
    int max = log.max();
    int min = log.min();

    double counter = 3;
    //Variables outside of loop

    System.out.println("Write a number between " + max + " and " + min + ".");
    System.out.println("If your number is higher than " + max + ", it will be " + max + ". Vice versa for " + min + ".");
    System.out.println("If your number is higher than the random number, you win credits!");
    System.out.println("You start with 2 credits.");
    System.out.println("You lose if you hit 0 credits. Good luck!");
    //Introduction

    while(counter &gt; 0) {
    //Loop start
        double r = Math.random() * 10;
        float in = log.getIn(); //Error here
        //Random number generator, input

        double credit = 6 - in;
        //Credit Win generator



        if(in &gt; r) {

            counter = counter + credit;
            //Counter refresh

            System.out.println("Great job! The number was " + r + ".");
            System.out.println("You won " + credit + " credits. Nice.");
            System.out.println("Credit counter:" + counter + ".");
            //Winning messages

        }
        else  {

            counter = counter - 1;
            //Counter refresh

            System.out.println("Nearly, n00b! It was " + r + ", how did u no realize.");
            System.out.println("You lost 1 credits!");
            System.out.println("Credit counter:" + counter + ".");
            //Losing messages
        }

        if(counter &lt;= 0) {              
            System.out.println("Game over! Better luck next time.");    
            //Game ender
        }

    }

}
</code></pre>

<p>}</p>

<p>Second class: RNGlog</p>

<pre><code>import java.util.Scanner;

public class RNGlog {

int max() {
    int max = 6;
    return max;
}

int min() {
    int min = 0;
    return min;
}

float getIn() {
    Scanner scan = new Scanner(System.in);
    float imp = scan.nextFloat();   //Error here            

    if(imp &lt; min()) {
        imp = min();            
    }
    //Stops number lower than 0

    if(imp &gt; max()) {
        imp = max();
    }
    //Stops numbers higher than 6   
        scan.close();
    return imp;


}
</code></pre>

<p>}</p>

<p>Would be really apriciated if someone could help!</p>
