fork(31) 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. String s = "137\n-104\n2 58\n +0\n++3\n+1\n 23.9\n2000000000\n-0\nfive\n -1";
  13. Reader reader = new StringReader(s);
  14. for (Integer x : new SolutionIter(reader))
  15. {
  16. System.out.println(x);
  17. }
  18. }
  19. }
  20.  
  21. class SolutionIter implements Iterable<Integer>
  22. {
  23. private Reader inp;
  24. public SolutionIter(Reader inp)
  25. {
  26. this.inp = inp;
  27. }
  28.  
  29. public Iterator<Integer> iterator()
  30. {
  31. return new NumberIterator();
  32. }
  33.  
  34. // Inner class
  35. private class NumberIterator implements Iterator<Integer>
  36. {
  37. private List<Integer> list = new ArrayList<Integer>();
  38. private Reader input;
  39. private int pos=-1;
  40.  
  41. public NumberIterator()
  42. {
  43. this.input = SolutionIter.this.inp;
  44. list = read(input);
  45. list.get(0);
  46. }
  47.  
  48. public boolean hasNext()
  49. {
  50. try
  51. {
  52. int a = list.get(pos+1);
  53. return true;
  54. }
  55. catch(Exception ex)
  56. {
  57. return false;
  58. }
  59.  
  60. }
  61.  
  62. public void remove() {
  63. }
  64.  
  65. public Integer next()
  66. {
  67. try
  68. {
  69. pos++;
  70. return list.get(pos);
  71.  
  72. }
  73. catch(Exception ex)
  74. {
  75. throw new NoSuchElementException();
  76. }
  77. }
  78.  
  79. private List<Integer> read(Reader input)
  80. {
  81. char c;
  82. List<Integer> integers = new ArrayList<Integer>();
  83. String iputString = "";
  84. try
  85. {
  86. int data = input.read();
  87. while (-1 != data)
  88. {
  89. char dataChar = (char) data;
  90. iputString += dataChar;
  91. data = input.read();
  92. }
  93. }
  94. catch(IOException ex)
  95. {
  96. //Do Nothing
  97. }
  98.  
  99. String[] lines = iputString.split("\\r?\\n");
  100. for(String st : lines)
  101. {
  102. st= st.trim();
  103. try
  104. {
  105. int a = Integer.parseInt(st);
  106. if(a >=-1000000000 && a<=1000000000)
  107. {
  108. integers.add(a);
  109. }
  110. }
  111. catch(Exception ex)
  112. {
  113. // Do Nothing
  114. }
  115.  
  116. }
  117.  
  118. return integers;
  119. }
  120. }
  121.  
  122. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
137
-104
0
1
0
-1