Could you please help me solve this java algorithm?
the idea is to create a method that counts a number from -5 to 30 and then it goes down -1 till reaches -5 then starts again
for example method should return: -5, 0, 5, 10, 15, … , 25, 30, 29, 28, 27, … , -3, -4, -5, 0, 5,..
I have tried the following, but still I cant find a solution.
--
double a = -5;
public double methodx(){
boolean positiveDirection = true;
if(positiveDirection == true) {
if(a != 30) {
a += 5 ;
positiveDirection=false;
return a;
}
else {
a -= 1;
positiveDirection=false;
}
}return a;
methodx? This is missing a loop somewhere.double? Useintfor this case.positiveDirectionshould be stored outside of the method because now it will always be set to true