I write a code in netbeans with the purpose of calculating the area of a pentagon, I wrote it with all the variables of type double. The problem is that when I enter a double to test the code the application prompt a mismatch exception.
I enter an int variable and it works, I have tried to change the code but it doesn't work.
package ejercicios.de.practica.capitulo4_5;
import java.util.Scanner;
public class EjerciciosDePracticaCapitulo4_5 {
public static void main(String[] args) {
// Crear variables
double Area, s, r;
final double PI= 3.1416;
final double TREINTAYSEIS= PI/5;
Scanner input= new Scanner (System.in);
System.out.println(" Enter the lenght from a center to a vertex of the pentagon: ");
r= input.nextDouble();
s= 2*r*(Math.sin(TREINTAYSEIS));
Area= (5*(Math.pow(s,2)))/4*(Math.tan(TREINTAYSEIS));
System.out.println("The area of the pentagon is " + Area);
}
}
If I enter the length from the center to a vertex: 5.5 the area of the pentagon is expected to be 71.92, but in my program, it doesn't accept the double input. I have to enter the int 5 and the result was 37.7007586539534.