如何调用方法进行计算 [英] How to call a method for doing a calculation

查看:105
本文介绍了如何调用方法进行计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想插入半径并将半径传递给calare mthod并获得结果并显示在区域中。



所有数据类型都是双倍的。 />


但这不起作用。



我尝试了什么:



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;
        
        }
    }
}

推荐答案

据我所知(at倾向于Java 7)Java不支持嵌套方法。所以你必须写一些类似的东西:

(请注意,入口点应声明为 main ,全部小写)



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)

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;

    }
}


这篇关于如何调用方法进行计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆