Write a method that returns the index of the last value in the array that is a multiple of 3.
For example, in the array
[4, 7, 9, 7, 12] the last multiple of three is ‘12’, which occurs at index 4.
This is my code so far. Could anyone help me revising my code?
public int findMultipleOfThree(int[] arr)
{
int result = 0;
for (int i = arr.length-1; i > 0; i--)
{
if(i%3==0)
{
result = arr[i];
}
}
return result;
}
I know this is far from the right answer. Please help