﻿ Java exercises: Create the area of a pentagon - w3resource # Java Method Exercises: Create the area of a pentagon

## Java Method: Exercise-14 with Solution

Write a Java method to create the area of a pentagon.

Pictorial Presentation: Sample Solution:

Java Code:

``````import java.util.Scanner;
public class Exercise14 {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);
System.out.print("Input the number of sides: ");
int n = input.nextInt();
System.out.print("Input the side: ");
double side = input.nextDouble();

System.out.println("The area of the pentagon is " + pentagon_area(n, side));
}

public static double pentagon_area(int n, double s) {
return  (n * s * s) / (4 * Math.tan(Math.PI/n));
}
}
```
```

Sample Output:

```Input the number of sides: 5
Input the side: 6
The area of the pentagon is 61.93718642120281
```

Flowchart: Java Code Editor:

Contribute your code and comments through Disqus.

What is the difficulty level of this exercise?

﻿