Assignment #106
Code
/*
jack newsom
period 5
program PrimeNum
filename PrimeNum.java
date completed 11/9/2015
*/
/* https://www.reddit.com/r/programmingbydoing/comments/22mcv7/113_finding_prime_numbers_need_help/ */
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