I am supposed to change an ordinary for loop into an enhanced for each loop. I have the following two problems:
1. for(int i = 1; i<data.length; i++)
sum = sum + data;
2. for(int i = 0; i<data.length; i++)
if(data == target)
return i;
These are the only pieces of information given, I am just supposed to rewrite them in "for each" form. Thus far I have:
1. nothing - I can't figure out how to exclude the first element aka data[0]
2. for(x : data)
{
if(x==target)
return
however I don't know what to enter after the return in order to return the value of i, and not the value of data
I would love any hints/input, I have been struggling for a while now and can't figure any of these out.