Guest User

Untitled

a guest
Oct 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. public static void main(String[] args) {
  2.  
  3. int i ,counter;
  4. //int arr[] = null;
  5. ArrayList<Integer> arr = new ArrayList<Integer>();
  6. for(counter=101 ; counter <999;counter++){
  7. boolean check = true ;
  8. for(i=2;i<counter;i++){
  9. if(counter%i == 0){
  10. check = false;
  11. break;
  12. }
  13.  
  14. }
  15. if(check){
  16.  
  17. for(int index = 0;index<=arr.size();index++){
  18. arr.add(counter);
  19. }
  20. }
  21.  
  22. }
  23.  
  24.  
  25. System.out.println(arr.get(arr.size()-1));
  26. }
  27.  
  28. Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
  29. at java.util.Arrays.copyOf(Unknown Source)
  30. at java.util.Arrays.copyOf(Unknown Source)
  31. at java.util.ArrayList.grow(Unknown Source)
  32. at java.util.ArrayList.ensureExplicitCapacity(Unknown Source)
  33. at java.util.ArrayList.ensureCapacityInternal(Unknown Source)
  34. at java.util.ArrayList.add(Unknown Source)
  35. at Prime.main(Prime.java:23)
Add Comment
Please, Sign In to add comment