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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Calling a Method with my Hexagon Area Calculator

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default 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).
    Improving the world one idiot at a time!

Similar Threads

  1. Replies: 5
    Last Post: August 10th, 2013, 03:21 PM
  2. Method not calling?
    By NTWolf1220 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 20th, 2013, 12:04 PM
  3. calling this method
    By antnas in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 2nd, 2012, 01:32 PM
  4. Area calculator.
    By LoganC in forum What's Wrong With My Code?
    Replies: 10
    Last Post: September 22nd, 2012, 07:15 PM
  5. [SOLVED] method calling
    By javapenguin in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 4th, 2010, 01:43 AM

Tags for this Thread