I was doing a simple test. Trying to find the area and volume of a cylinder. When I put however decimals as an input I get the bellow error:
> Exception in thread "main" java.util.InputMismatchException
at java.base/java.util.Scanner.throwFor(Scanner.java:939)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextDouble(Scanner.java:2564)
at Test2.Test2.main(Test2.java:10)
I already listed in the code that I am able to get decimals as an input by using the .nextDouble() method, however, I do not know why that does not work. When I, however, place integers as input the program runs correctly.
package Test2;
import java.util.*;
public class Test2 {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
final double PI = 3.14159;
System.out.print("Enter the radius and the length of a cylinder: ");
double radius = input.nextDouble();
double length = input.nextDouble();
double area = radius * radius * PI;
double volume = area * length;
System.out.println("The area is "+ area);
System.out.println("The volume is "+ volume);
}
}
I would really appreciate it if someone could help me. Thanks in advance