In Java, what is meant by this "double cannot be dereferenced" error? -


this question has answer here:

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

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -