import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { String string = scanner.nextLine(); String[] strings = string.split(" "); if (strings.length == 1) { int n = Integer.parseInt(strings[0]); if (n == 0) { break; } else { for (int i = 1; i <= n; i++) { if (i == 1) { System.out.print(i); } else { System.out.print(" " + i); } } System.out.println(); } } if (strings.length == 2) { int m = Integer.parseInt(strings[0]); int n = Integer.parseInt(strings[1]); if (m <= n) { for (int i = m; i <= n; i++) { if (i == m) { System.out.print(i); } else { System.out.print(" " + i); } } System.out.println(); } else { for (int i = m; i >= n; i--) { if (i == m) { System.out.print(i); } else { System.out.print(" " + i); } } System.out.println(); } } if (strings.length == 3) { int m = Integer.parseInt(strings[0]); int n = Integer.parseInt(strings[1]); int s = Integer.parseInt(strings[2]); if (m <= n) { for (int i = m; i <= n; i = i + s + 1) { if (i == m) { System.out.print(i); } else { System.out.print(" " + i); } } System.out.println(); } else { for (int i = m; i >= n; i = i - s - 1) { if (i == m) { System.out.print(i); } else { System.out.print(" " + i); } } System.out.println(); } } } } } |
Double click to view unformatted code.