package class9_2_GeneratingHashCodes_021; // Josiah Yoder, MSOE, 06 May 2015 import java.util.Scanner; public class PrimesAndCollisions { /** * Demo driver for the testStep function. See below * @param args ignored */ public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter array size (q to quit): "); while(in.hasNextInt()) { int size = in.nextInt(); System.out.print("Enter step: "); if(in.hasNextInt()) { int step = in.nextInt(); testStep(size, step); System.out.println("Enter a step size: (q to quit)"); } } } /** * Create an empty array of size size. * * Starting with index 0, step through the array, step items at a time, filling in * each place we land. * @param size size of array * @param step number added to previous index to get next index to fill. */ private static void testStep(int size, int step) { boolean[] array = new boolean[size]; int curr = 0; int count = 0; while(!array[curr]) { array[curr] = true; System.out.println("curr:"+curr); curr+=step; curr%=size; count++; } System.out.println("steps: "+count); System.out.println("Load factor: "+ (double)count/size); } }