fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Stairs s = new Stairs(5, 10);
  13.  
  14. for (int i = 0; i <= 20; ++i) {
  15. System.out.println(s.next());
  16. }
  17. }
  18. }
  19.  
  20. class Stairs {
  21. private int min;
  22. private int max;
  23. private int diff;
  24. private int value;
  25.  
  26. public Stairs(int min, int max) {
  27. this.min = min;
  28. this.max = max;
  29. this.diff = max - min;
  30. this.value = diff - 1;
  31. }
  32.  
  33. public int next() {
  34. value = (value + 1) % (2 * diff);
  35. return min + Math.abs(value - diff);
  36. }
  37. }
  38.  
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
5
6
7
8
9
10
9
8
7
6
5
6
7
8
9
10
9
8
7
6
5