methods - 如何将返回值从一种方法传递给另一种方法?
问题描述
我需要将 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;
}
解决方案
要在表达式中使用函数的返回值,只需在此处调用函数,即:
public double groundSpeed()
{
return Math.sqrt( Math.pow(va, 2) + Math.pow(vw, 2)
- 2 * va * vw * Math.cos(Math.toRadians(d - w - windCorrectionAngle()))
);
}
推荐阅读
- python - 多进程运行比单个进程慢
- android - 如何隐藏根视图,直到它准备好输入?
- imagemagick - 如何使用 ImageMagick 的识别实用程序格式化日期和时间?
- cryptography - 使用 ECC 生成私钥/公钥对:椭圆曲线
- java - 吸气剂工作不正常
- node.js - Sequelize.js 设置器方法不起作用
- php - 如何解决使用 php pdo 将所选选项存储到数据库中的错误
- templates - 敲除模板绑定项未定义
- r - R - 在数据集的所有行中应用一个函数(combinevar)
- windows - 如何在 Windows Anaconda 上安装 Dryscrape?