Created
June 17, 2016 12:52
-
-
Save Yurlov/8a8706330813690d1df8ea849161e0e0 to your computer and use it in GitHub Desktop.
Prog.kiev.ua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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