1

I am trying to kick start this coding but facing below error messages:

Exception in thread "main" 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 Analysis.main(Analysis.java:17)

import java.util.Scanner;

public class Analysis
{
  public static void main(String[] args)
  {
    Scanner input = new Scanner(System.in);

    int passes = 0;
    int failures = 0;
    int studentCounter = 0;


    while (studentCounter <= 10)
    {
      System.out.print("Enter result (1 = pass, 2 = fail): ");
      int result = input.nextInt();

      if (result == 1)
        passes = passes + 1;
      else
        failures = failures + 1;

      studentCounter = studentCounter + 1;
    }

    System.out.printf("Passed: %d%nFailed: %d%n", passes, failures);

    if (passes > 8)
      System.out.println("Bonus");
  }
}

Can someone please tell me solution? Thanks.

Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
small man
  • 11
  • 1
  • 2
    What's your input? – retatu Jul 20 '18 at 17:21
  • You have most likely configured your environment so that this program is started with a closed standard input (or using an empty file as standard input, which is the same thing). That is very unusual and would normally not happen unless you chose to set everything up outside of the norm. You'll need to describe everything about how you're running your code. – kumesana Jul 20 '18 at 17:22
  • Maybe this will help https://stackoverflow.com/a/13042296/8413677 – Dmitry Surin Jul 20 '18 at 17:29
  • how to key in the input? I thought the system will only prompt me to key in the input after I run the programme. – small man Jul 23 '18 at 01:15
  • I key in the code at https://www.compilejava.net/ – small man Jul 23 '18 at 01:17
  • I key in the code at https://www.compilejava.net/ , so does the platform caused to this problem? – small man Jul 23 '18 at 01:18

0 Answers0