Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class InsertSort{
- int rnd;
- public InsertSort(){
- int count = 0;
- int[] rndNums = new int [100];
- while(count < 100){
- rnd = (int) (Math.random() * 200 + 1);
- if(isAPrime(rnd) == true){
- rndNums[count] = rnd;
- for(int w = 0; w < rndNums.length; w++){
- if(rndNums[count] == rndNums[w]){
- count --;
- }
- }
- count++;
- }
- }
- for (int i = 0; i<rndNums.length; i++){
- System.out.println(" " + rndNums[i]);
- }
- insertionSort(rndNums);
- }
- public void insertionSort(int[] a){
- for(int i = 1; i<a.length; i++){
- int key = a[i];
- int j = i-1;
- while(j >= 0 && a[j] < key){
- a[j+1]=a[j];
- j--;
- }
- a[j+1] = key;
- }
- }
- public boolean isAPrime(int y){
- int num = 2;
- boolean isAPrime = true;
- //System.out.println ("Put in a number plz mayne");
- //Scanner.scan.nextint;
- while (num<y){
- if (y%num==0){
- return false;
- }
- num++;
- }
- return isAPrime;
- }
- }
Add Comment
Please, Sign In to add comment