sorter

/** * Write a description of class Insertion here. * * @author (your name) * @version (a version number or a date) */ import java.util.*; import java.util.Scanner; public class Insertion { public Insertion(){ int[] arr = {35,6,2,12,3,27,10,56,7,21,28,50,32,41,1,5,8,90,1}; int c = 0; int[] num = new int[10]; while (c < 10){ int random = (int)(Math.random() * 100 + 1); if (isAPrime(random) == true){ num[c] = random; c++; } } System.out.println(Arrays.toString(num)); for(int i = 1; i < num.length; i++){ int key = num[i]; int b = i - 1; while(b>=0 && num[b] > key){ num[b+1] = num[b]; b--; } num[b+1] = key; } System.out.println(Arrays.toString(num)); } public boolean isAPrime(int y) { boolean isAPrime=true; int num=2; while(num<y){//can do y/2 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.