Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

Thread: Calling a Method with my Hexagon Area Calculator

1. Calling a Method with my Hexagon Area Calculator

I have the following code. I am learning methods and need to create a separate method so I can call a method that will calculate the area of the regular hexagon based on the input ( the side given ).

```import java.util.*;

public class HexagonAreaCalculator {

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

System.out.println("Enter the side of a hexagon");
double side = input.nextDouble();

float area = (float) ((( 3 * Math.pow(3, .5) * Math.pow(side, 2))) / 2);
if (side == 0)
System.out.println("Nope uh uh u can't do that");
else

System.out.println("The area is " + area);

}

//public static float hexArea(float a) {

//}
}```

2. Re: Calling a Method with my Hexagon Area Calculator

You currently have code calculating the area inside the main method but it should be in the hexArea method. So you need to move your code into that method and then call it from the main method. Don't forget to do something with the returned value (major mistake of learners).