Skip to content

Instantly share code, notes, and snippets.

@Yurlov
Created June 17, 2016 12:52
Show Gist options
  • Save Yurlov/8a8706330813690d1df8ea849161e0e0 to your computer and use it in GitHub Desktop.
Save Yurlov/8a8706330813690d1df8ea849161e0e0 to your computer and use it in GitHub Desktop.
Prog.kiev.ua
import java.util.Scanner;
public class RangeWithStepPrinter{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int first = in.nextInt();
int last = in.nextInt();
int step = in.nextInt();
if(first<last){
if(first<last&&step<0){
throw new IllegalArgumentException("Sorry");
}
for (int i = first;i<=last;i+=step){
System.out.println(i);
}
}else if(first>last){
for (int i = first;i>=last;i+=step){
System.out.println(i);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment