I have to make x greater than-equal to y with the constant d, in java it tells me that the variable I created "steps" must return outside the while but then the if would not work for me
public static int saltos(int x, int y, int d) // x=10 - y = 85 d = 30
{
int pasos = 0;
int brincos = 0;
while(x<=y)
{
brincos = x+d;
pasos++;
if(brincos >= y)
return pasos;
}
}
In addition to Alfabravo's clear answer, your variable
brincos
must accumulate the values ofx+d
in each iteration of your loop, otherwise you will have a loop because each time you jump it will be x+d = 40