-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRangeWithStepPrinter
More file actions
25 lines (22 loc) · 981 Bytes
/
RangeWithStepPrinter
File metadata and controls
25 lines (22 loc) · 981 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.util.Scanner;
public class RangeWithStepPrinter {
public static void main(String[] args) throws IllegalAccessException {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter firs namber: ");
int firstnumber = scanner.nextInt();
System.out.println("Enter second number:");
int seconnumber = scanner.nextInt();
System.out.println("Enter step: ");
int step = scanner.nextInt();
scanner.close();
if (firstnumber < seconnumber && step > 0) {
for (int numberplus = firstnumber; numberplus < seconnumber; numberplus += step)
System.out.println(numberplus);
} else if (seconnumber < firstnumber) {
for ( int numberminus = firstnumber; numberminus>seconnumber; numberminus += step)
System.out.println(numberminus);
} else {
throw new IllegalAccessException("Incorrectly entered step");
}
}
}