import java.util.Scanner;

/**
 * This program finds the smallest non-prime number generated by the formula
 * y = x^2 - x + 41.
 **/
public class Prime_Formula {
    // This is a very inefficient, but easy to write prime check algorithm
    public static boolean check_If_Prime(int p) {
        int i = 2;
        boolean m = true;

        // If the number is 1 or 0, it's not prime
        if (p == 1 || p == 0) {
            return false;
        } else {
            while (i < p && m == true) {
                // If the number has a factor, it isn't prime
                if (p % i == 0) {
                    m = false;
                } else {
                     i++;
                }
            }
            return m;
        }
    }

    public static void main(String[] args) {
        System.out.println("Prime Generating Formula");
        int x = 0, y;
        boolean flag = true;

        // if and while require boolean statements as their arguments.
        // Boolean variables, however, also work, e.g.,
        // while (flag == true) {
        while (flag) {
            y = (x * x) - x + 41;
            if (check_If_Prime(y)) {
                x++;
            } else {
                flag = false;
            }
        }
        System.out.println("The value of x when y is non-prime is " + x);
    }
}

Add problem 8 to unit 2
Add problem 8 to unit 2
