Java trouble with conversion of int to double


#1

        for(double dec : temperature) {
         System.out.printf("%6.1f", temperature[dec]);
        }

I'm learning for: each loops in Java. Having trouble with this particular line. I have defined the array temperature already as:

        double [] temperature = new double[length];

It's reading in from a file of decimals with 1 number after the decimal point. Why is my code not working? I am not converting from a double to an int, but my error message is as follows:

HeatIndex.java:110: error: incompatible types: possible lossy conversion from double to int
         System.out.printf("%6.1f", (double)temperature[dec]);
                                                        ^
1 error

#2

When my own deficiencies get in the way, there is always search:

https://www.google.ca/search?q=java+int+to+double

double temperature[dec]

???


#3

That's true.
As to

I was trying to cast temperature of each item as a double to see if that helped, it did not.

I'm looking it up on stackoverflow, not finding anything atm.


#4

I'm actually such a moron sometimes, I figured it out. I was trying to do a manual loop but I was using a for each loop. What I really needed was:

        for(double dec : temperature) {
         System.out.printf("%6.1f", dec);
        }

Thanks so much for answering!