Circumference area

Asked

Viewed 61 times

0

Good evening! I’m starting in Java, and I’m trying to complete the Circumference Area Code of the URI. You’re giving a lot of trouble:

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 Main.main(Main.java:9)

This is the code.

import java.util.Scanner;
public class Main
{
    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        double raio = scan.nextDouble();
        double n = 3.14159;
        double area = Math.pow(raio,2) * n;

        System.out.println("A=" +area);

    }
}

What am I doing wrong? Thanks in advance.

  • I copied and pasted your code here and ran normal. It may be a problem on the challenging site... Also, it may be that you haven’t filled in the entry...

1 answer

1


For documentation:

public double nextDouble()
Scans the next token of the input as a double. This method will throw InputMismatchException if the next token cannot be translated into a valid double value. If the translation is successful, the scanner advances past the input that matched.
If the next token matches the Float regular expression defined above then the token is converted into a double value as if by removing all locale specific prefixes, group separators, and locale specific suffixes, then mapping non-ASCII digits into ASCII digits via Character.digit, prepending a negative sign (-) if the locale specific negative prefixes and suffixes were present, and passing the resulting string to Double.parseDouble. If the token matches the localized NaN or infinity strings, then either "Nan" or "Infinity" is passed to Double.parseDouble as appropriate.

Returns:
the double scanned from the input
Throws:
InputMismatchException - if the next token does not match the Float regular expression, or is out of range
NoSuchElementException - if the input is exhausted
IllegalStateException - if this scanner is closed

There it says that, to be launched a NoSuchElementException, is because the entry "is over". Probably missing something to be filled in as input.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.