PROGRAMMING AND CODE


Assignemnt #106

Code

/// Name: Justin Li
/// Period: 7
/// Program Name: PrimeNum
/// Date Completed: 3/27/16

public class PrimeNum
{
    public static void main( String[] args )
    {
        for ( int n = 1; n <= 20; n++ )
        {
            if (isPrime(n)) {
                System.out.println( n + " <");

            } else {
                System.out.println( n );
            }
        }   
    }

    public static boolean isPrime (int n )
    {
        for (int x = 2; x < n;x++)
        {
            if (n%x == 0) 
            {
                return false;
            }
        }
        return true;
    }
}  
    

Picture of the output

Assignment 1