【问题标题】:How do I pass a return value from one method to another?如何将返回值从一种方法传递给另一种方法?
【发布时间】:2018-12-24 17:36:16
【问题描述】:

我需要将 windCorrectionAngle 方法的返回值传递给 groundSpeed 方法,并将其放在表达式的最后(“windCorAng”)。这是唯一对我不起作用的部分。据我了解,这不是 Java 可以轻松完成的事情,因为它看不到其他方法的返回。很想学习如何做到这一点以及什么是正确的做法。我有一个简单的打印行来获取 grSpd 的结果。

public double windCorrectionAngle()
{
double windCorAng = Math.toDegrees(Math.asin 
( vw * Math.sin( Math.toRadians (w-d) ) / va) ); 
return windCorAng;
}

public double groundSpeed()
{
double grSpd = Math.sqrt( Math.pow(va,2) + Math.pow(vw,2) - 2 * va * vw * 
Math.cos(Math.toRadians(d - w - windCorAng))); 
return grSpd;
}

【问题讨论】:

    标签: methods parameters return


    【解决方案1】:

    要在表达式中使用函数的返回值,只需在此处调用函数,即。即:

    public double groundSpeed()
    {
        return Math.sqrt( Math.pow(va, 2) + Math.pow(vw, 2)
                        - 2 * va * vw * Math.cos(Math.toRadians(d - w - windCorrectionAngle()))
                        ); 
    }
    

    【讨论】:

      猜你喜欢
      • 2022-11-29
      • 1970-01-01
      • 2017-07-29
      • 1970-01-01
      • 2017-03-19
      • 2014-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多