我有以下代码:
public class RandomCompliment {
static final String[] comps = { "gorgeous butterfly!", "strawberry milkshake!", "calm waterfall", "smart cookie", "big genius", "friendly cat" };
public static void main(String[] args) {
for (int i = 0; i < 200 ; i++ ) {
System.out.print("Good monring, " + comps[(((20) * Math.sin(i)).intValue()) % comps.length]);
}
}
}
它给了我这个错误:
C:\Misc_Stuff\RandomScratch>javac RandomCompliment.java RandomCompliment.java:14: double cannot be dereferenced System.out.print(" " + comps[ ( ((20) * Math. sin(i)).intValue() ) % comps.length ]);
^ 1 error
这里的“取消引用”是什么意思?
最佳答案
Math.sin(i)
返回 double
。您无法在 double
(或任何原始数据类型)上调用方法 (intValue()
)。相反,您可以将 double
向下转换为 int
:
(int) (20 * Math.sin(i))
关于java - 在Java中,这个 "double cannot be dereferenced"错误是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33463421/