```java
import java.util.*;

public class Main {
  static void factorFinder() {
    Scanner sc = new Scanner(System.in);
    boolean valid = false;
    int number = 0;

    while(! valid ){
      System.out.println("Enter the number you want to find the factor of(Numbers only)");
      try {
        number = sc.nextInt(); 
        valid = true;
      } catch (InputMismatchException e) {
            System.out.println("Not a number.");
            sc.next();
    }
      }
    sc.close();

    System.out.print("Factors of " + number + " are: ");
    for (int i = 1; i <= number; ++i) {

      // if number is divided by i
      // i is the factor
      if (number % i == 0) {
        System.out.print(i + " ");
      }
    }
  }
  public static void main(String[] args) {
    Scanner choiceScanner = new Scanner(System.in);
    System.out.println("Do you want to use the factor finder? (y/n)");
    String answer = choiceScanner.nextLine();
    choiceScanner.close();
    if(answer.equals("y")){
      factorFinder();
    }else{
      System.exit(0);
    }
    }
}

```

Here is the terminal output(Ran through replit)

```
 sh -c javac -classpath .:target/dependency/* -d . $(find . -type f -name '*.java')
 java -classpath .:target/dependency/* Main
Do you want to use the factor finder? (y/n)
y
Enter the number you want to find the factor of(Numbers only)
Exception in thread "main" java.util.NoSuchElementException
    at java.base/java.util.Scanner.throwFor(Scanner.java:937)
    at java.base/java.util.Scanner.next(Scanner.java:1594)
    at java.base/java.util.Scanner.nextInt(Scanner.java:2258)
    at java.base/java.util.Scanner.nextInt(Scanner.java:2212)
    at Main.factorFinder(Main.java:13)
    at Main.main(Main.java:38)
exit status 1
 

```

I am making a calculator that finds the factor of a given number. The calculator part is done and is working. However, the part where it asks to use the calculator isn't working. It gave a NoSuchElementException error. Can someone maybe help me on this?