In Java, what is meant by this "double cannot be dereferenced" error? -
this question has answer here:
- double cannot dereferenced? 3 answers
i have following code :
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) { (int = 0; < 200 ; i++ ) { system.out.print("good monring, " + comps[(((20) * math.sin(i)).intvalue()) % comps.length]); } } }
and giving me error :
c:\misc_stuff\randomscratch>javac randomcompliment.java randomcompliment.java:14: double cannot dereferenced system.out.print(" " + comps[ ( ((20) * math. sin(i)).intvalue() ) % comps.length ]);
^ 1 error
what meant "dereferenced" here ?
math.sin(i)
returns double
. cannot invoke method (intvalue()
) on double
(or primitive data-type). instead, can down-cast double
int
:
(int) (20 * math.sin(i))
Comments
Post a Comment