Guest User

Untitled

a guest
May 19th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.60 KB | None | 0 0
  1.  
  2. import java.util.*;
  3.  
  4. public class psx {
  5.  
  6.     public static void noexc(int n) {
  7.         int[] a = new int[0];;
  8.         for (int i : new Range(n)) {
  9.             if (a.length > 0) {
  10.                 int fp = a[1];
  11.             }
  12.         }
  13.     }
  14.  
  15.     public static void exc(int n) {
  16.         int[] a = new int[0];
  17.         for (int i : new Range(n)) {
  18.             try {
  19.                 int fp = a[1];
  20.             } catch (java.lang.ArrayIndexOutOfBoundsException e) {
  21.                 continue;
  22.             }
  23.         }
  24.     }
  25.  
  26.     public static void main(String[] args) {
  27.         int n = 128 * 1024 * 1024;
  28.         if (args.length > 0) {
  29.             noexc(n);
  30.         } else {
  31.             exc(n);
  32.         }
  33.     }
  34.  
  35. }
  36.  
  37. class Range implements Iterable<Integer> {
  38.  
  39.     private int limit;
  40.  
  41.     public Range(int limit) {
  42.         this.limit = limit;
  43.     }
  44.  
  45.     @Override
  46.     public Iterator<Integer> iterator() {
  47.         final int max = limit;
  48.         return new Iterator<Integer>() {
  49.  
  50.             private int current = 0;
  51.  
  52.             @Override
  53.             public boolean hasNext() {
  54.                 return current < max;
  55.             }
  56.  
  57.             @Override
  58.             public Integer next() {
  59.                 if (hasNext()) {
  60.                     return current++;
  61.                 } else {
  62.                     throw new NoSuchElementException("Range reached the end");
  63.                 }
  64.             }
  65.  
  66.             @Override
  67.             public void remove() {
  68.                 throw new UnsupportedOperationException("Can't remove values from a Range");
  69.             }
  70.         };
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment