Tell me what I'm missing?
Input Arguments
1, 8, 2
8, 1, -2
1, 8, -2
Result
1 3 5 7
8 6 4 2
IllegalArgumentException
My code:
package com.Star;
public class Main {
public static void main(String[] args) {
rangeWithStepPrinter(1,8,5);
rangeWithStepPrinter(8,1,-2);
rangeWithStepPrinter(1,8,-2);
}
public static void rangeWithStepPrinter(int first, int last, int i) {
if (first < last) {
for (i = first; i <= last; i += +2) {
System.out.print(i + " ");
}
}
if (first > last) {
for (i = first; i >= last; i += -2) {
System.out.print(i + " ");
}
}
System.out.println();
}
}