Assignment 106, Prime Method
Code
///Name: Stella Koliavas
///Period: 5
///Program Name: Prime
///File Name: Prime.java
///Date Finshed: 4/29/16
import java.util.Scanner;
public class Prime
{
public static void main( String[] args )
{
for ( int n = 2 ; n <= 20 ; n = n+1 )
{
if (isPrime(n)== true)
System.out.println(n);
else
System.out.println(n + "<");
}
}
public static boolean isPrime( int n )
{
boolean result = false;
for ( int x = 2 ; x <= n ; x = n+1 )
{
if ( n%x == 0 )
result = true;
else
result = false;
}
return result;
}
}
Picture of the output