I'm writing a code segment that calculates and displays the number of holes upon which a golfer made an eagle. Which is two fewer than the par value for the hole. This is what I have come up with.
int[] par = new int[18];
int[] strokes = new int[18];
for (int i = 0; i < par.length; i++)
{
par[i] = (int)(Math.random() * 2) + 1; //calculates eagle
strokes[i] = (int)(Math.random() * 5) + 1; //calculates number of strokes per hole
}
for (int i = 0; i < strokes.length; i++)
if (par[i] > strokes[i])
System.out.println(i + 1);
Is it correct or am I making an error somewhere?