0

Here's the error that I'm getting for a simple program that gets a pound value and returns it as Kg:

Enter a pound value:
    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.nextDouble(Scanner.java:2413)
        at returnType2.main(returnType2.java:12)

And here's the code:

import java.util.Scanner;

      public static void main (String args[]) throws Exception 
      {
        Scanner myScanner = new Scanner(System.in);

        double pound, kg;
        System.out.println("Enter a pound value:");
        pound = myScanner.nextDouble();
        kg = convertToKg (pound);
        System.out.println("In kilograms:");
        System.out.println(kg);
      }

        public static double convertToKg (double num)
        {
          double kg;
          kg = (num * 2.2);
          return kg;
        }
APSmoove
  • 3
  • 1
  • You didn't provide required input. You get this error in OnlineIDEs when you don't provide the required inputs to the code and try to execute it. Give the link of uploaded code. – Sanket Makani Jun 10 '17 at 15:48
  • Duplicate - [Scanner next() throwing NoSuchElementException for some online compilers](https://stackoverflow.com/questions/39766488/scanner-next-throwing-nosuchelementexception-for-some-online-compilers) – Bernhard Barker Jun 10 '17 at 16:05

0 Answers0