[英]Java - How to perform operations on a value in an array?
This is the operation i am trying to do. 这是我正在尝试执行的操作。 I get the error "bad operand types for binary operator "*". 我收到错误“二进制运算符“ *”的错误操作数类型)。
How do i pass this calcualtion? 我如何通过此计算? Can somone show me an example of how to do this? somone可以告诉我如何执行此操作的示例吗? Note that day[i] has all its values already in it. 请注意,day [i]已包含所有其值。
The complaint is that day[i]*9
doesn't make any sense. 抱怨是day[i]*9
没有任何意义。 This must be because day[i]
isn't a numerical type. 这必须是因为day[i]
不是数字类型。
If day
is also of type Temperature[]
, then you can't multiply day[i]
by anything because it's an object, not a number. 如果day
的类型也为Temperature[]
,则您不能将day[i]
乘以任何值,因为它是一个对象,而不是数字。 You'll need to write a method of Temperature
that allows you to read the value stored there: 您需要编写一个Temperature
方法,该方法允许您读取那里存储的值:
public class Temperature {
private double temp;
// constructors etc.
public double getTemp() {
return temp;
}
}
Now you can use 现在您可以使用
(day[i].getTemp()*9)/5+32
to get what you want. 得到你想要的。 Note that I've set the type as double
, because it looks like you'll want floating point arithmetic here. 请注意,我将类型设置为double
,因为看起来您将在这里使用浮点运算。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.