One of my homework assignments was to write a small enhanced for-loop with floats. I understand the basis of this loop style with integer arrays, to my understanding:
for (int i = 0; i < some.number; i++)
is equivalent to
for (int i : array_example)
If this is accurate how is this supposed to work with a array filled with floats? I thought the incremental operator (i++
) was only allowable with integers. Just looking for some clarification.
Thanks.
EDIT: Here's an example of what I'm doing, and what Eclipse doesn't like. Which is probably adding to my confusion:
public class java_array
{
public static void main(String[] args)
{
float[] values = {1/2,1/3,5/3};
float total = 0;
for (float i : values)
{
values[i] = i; //Getting an error here "can't convert from float to int.
}
for (float i : values)
{
System.out.println(values[i]); //Getting an error here "can't convert from float to int.
}
}
}
Everything has been declared as float
. Why is the IDE saying this?