Insertion

import java.util.*; public class InsertSort { int random; public InsertSort(){ int count = 0; int[] nums = new int [10]; while(count < 10){ int random = (int)(Math.random() * 200 + 1); if(isAPrime(random) == true){ nums[count] = random; count++; } } for(int i = 0; i<nums.length; i++) { System.out.print(" " + nums[i]); } InsertSort(nums); } public void InsertSort(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+i]=a[j]; j--; } } } public boolean isAPrime(int y){ boolean isAPrime = true; int num = 2; while(num<y){ if(y%num==0){ return false; } num++; } return isAPrime; } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.