Assignment #106 and Finding Prime Numbers
Code
///Name: Tim Gibson
///Period: 6
///Project Name: Finding Prime Numbers
///File Name: Prime.java
///Date Finished: 12/1/15
public class Prime
{
public static void main ( String[] args )
{
boolean prime;
for ( int n = 2; n <= 100; n +=1 )
{
prime = isPrime(n);
if ( prime == true )
System.out.println(n);
}
}
public static boolean isPrime( int n )
{
boolean prime = true;
for ( int x = 2; x < n; x += 1 )
{
int y = ( n % x );
prime = ( y != 0 );
if ( prime == false )
x = n;
}
return prime;
}
}
Picture of the output