Guest User

Untitled

a guest
Nov 18th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. import java.util.*;
  2. public class InsertSort{
  3. int rnd;
  4. public InsertSort(){
  5. int count = 0;
  6. int[] rndNums = new int [100];
  7. while(count < 100){
  8. rnd = (int) (Math.random() * 200 + 1);
  9. if(isAPrime(rnd) == true){
  10. rndNums[count] = rnd;
  11. for(int w = 0; w < rndNums.length; w++){
  12. if(rndNums[count] == rndNums[w]){
  13. count --;
  14. }
  15. }
  16. count++;
  17. }
  18. }
  19. for (int i = 0; i<rndNums.length; i++){
  20.  
  21. System.out.println(" " + rndNums[i]);
  22. }
  23. insertionSort(rndNums);
  24. }
  25. public void insertionSort(int[] a){
  26. for(int i = 1; i<a.length; i++){
  27. int key = a[i];
  28. int j = i-1;
  29. while(j >= 0 && a[j] < key){
  30. a[j+1]=a[j];
  31. j--;
  32. }
  33. a[j+1] = key;
  34. }
  35.  
  36.  
  37. }
  38. public boolean isAPrime(int y){
  39. int num = 2;
  40. boolean isAPrime = true;
  41. //System.out.println ("Put in a number plz mayne");
  42. //Scanner.scan.nextint;
  43. while (num<y){
  44. if (y%num==0){
  45. return false;
  46. }
  47. num++;
  48. }
  49. return isAPrime;
  50. }
  51. }
Add Comment
Please, Sign In to add comment