Click here to Skip to main content
15,908,013 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to insert the radius and pass the radius to calare mthod and get the result and display in area.

All the data types are double.

But this is not working.

What I have tried:

//Calling Methods
package javalearning;

import static java.lang.Math.PI;
import java.util.Scanner;


public class CallingMethods {
    
    public static void Main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        
        //double PI = Math.PI;
        //double radius;
        //double area;
        double diameter;
        
        System.out.print("Enter the radius :");
        
        double radius=input.nextDouble();
        
        double area=calarea(radius);
        
        System.out.print("The are of the circle is");
        
        public double calarea(double radiusC)
        {
        double CArea;
        CArea=PI*radiusC*radiusC;
        return CArea;
        
        }
    }
}
Posted
Updated 5-Apr-17 21:30pm
v2

1 solution

As far as I know (at leant till Java 7) Java doesn't support nested methods. So you have to write something like:
(please note the entry point should be declared as main, all lowercase)

Java
public class CallingMethods {

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

        double diameter;

        System.out.print("Enter the radius :");

        double radius=input.nextDouble();

        double area=calarea(radius);

        System.out.println("The are of the circle is " + area);

    }

    public static double calarea(double radiusC)
    {
      double CArea;
      CArea=PI*radiusC*radiusC;
      return CArea;

    }
}
 
Share this answer
 
Comments
Member 13049972 6-Apr-17 3:37am    
Thanks brother this is working,but i corrected it as u mention but it doesn't work (IDK WHY) but then i copy and pasted it works , its kind a creepy .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900