fork(7) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone
  6. {
  7. private static void outputInterval(int a, int b) {
  8. System.out.println(String.format("[%d, %d]", a, b));
  9. }
  10.  
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. int a[] = new int[]{1,2,3,4,5,7,8,9,10,15,16,21,23,25,26};
  14. int intervalStart = a[0];
  15. for (int i = 1; i < a.length; ++i) {
  16. if (a[i] > a[i-1]+1) {
  17. outputInterval(intervalStart, a[i-1]);
  18. intervalStart = a[i];
  19. }
  20. }
  21. outputInterval(intervalStart, a[a.length-1]);
  22. }
  23. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
[1, 5]
[7, 10]
[15, 16]
[21, 21]
[23, 23]
[25, 26]