Patterns of Prime Numbers only
import java.util.Scanner;
public class PrimePattern
{
public static boolean isPrime(int n)
{
int i;
for(i=2;i<n;i++)
if(n%i==0)
return false;
return true;
}
public static void main(String args[])
{
int n, i, j, x=1;
Scanner sc=new Scanner(System.in);
System.out.print("Enter N: ");
n=sc.nextInt();
for(i=1;i<=n;i++)
{
for(j=1;j<=i;x++)
{
if(isPrime(x))
{
System.out.print(x+"\t");
j++;
}
}
System.out.println();
}
}
}
No comments
Post your comments