@@ -0,0 +1,1810 @@
+/**%0A * Created by Daniel Saunders on 2/6/15%0A * PrimeCheck.java%0A * A program that searches through each number %3C input integer, return a set of factors and%0A * determines whether or not the input integer is prime. This program has a time complexity%0A * of magnitude O(n/2), or O(n). %0A */%0A%0Aimport java.util.*;%0Aimport java.math.*;%0A%0Apublic class PrimeCheck %7B%0A%09%0A%09public static void main (String%5B%5D args) %7B%0A%09%09Scanner sc = new Scanner(System.in);%0A%09%09%0A%09%09while (true) %7B%0A%09%09%09System.out.print(%22Enter a positive integer n, or %5C%22exit%5C%22 to quit: %22); // input number to perform factorization check on%0A%09%09%09String input = sc.nextLine(); %0A%09%09%09if (input.equals(%22exit%22)) System.exit(0); // exits on %22exit%22 input%0A%09%09%09long n = 0;%0A%09%09%09try %7B%0A%09%09%09%09n = Long.parseLong(input); // accepts up to 2%5E64-1 size integers%0A%09%09%09%7D catch (NumberFormatException e) %7B%0A%09%09%09%09System.out.println(%22Not an integer. Try again!%22); // too large, bad format, not a number...%0A%09%09%09%09continue;%0A%09%09%09%7D%0A%09%09%09if (n %3C= 0) %7B // negative or zero input%0A%09%09%09%09System.out.println(%22Negative or zero. Try again!%22); %0A%09%09%09%09continue;%0A%09%09%09%7D%0A%09%09%09ArrayList%3CLong%3E factors = findFactors(n); // create list of factors from findFactors method%0A%09%09%09if (factors.size() %3C= 2) %7B%0A%09%09%09%09System.out.println(n + %22 is a prime number. Trivial factors: %22 + factors);%0A%09%09%09%7D%0A%09%09%09else %7B%0A%09%09%09%09System.out.println(n + %22 is not a prime number. Factors: %22 + factors);%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%09%0A%09public static ArrayList%3CLong%3E findFactors(long n) %7B  // method that loops through each number %3C input / 2, adds factors to factor list%0A%09%09ArrayList%3CLong%3E factors = new ArrayList%3CLong%3E();%0A%09%09for (long i = 1; i %3C= n / 2; i++) %7B // only necessary to go up to input / 2!%0A%09%09%09if (n %25 i == 0) %7B // no remainder = i divides input%0A%09%09%09%09factors.add(i);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09factors.add(n); // add input number to factors, input is trivially a factor%0A%09%09return factors;%0A%09%7D%0A%7D%0A

Create PrimeCheck.java