You are on page 1of 2

import java.util.

*;
public class p
{
int arr[];
int m, n;
p(int mm, int nn)
{
m = mm;
n = nn;
}
int iscomposite(int p)
{
int c = 0;
for(int i=1; i<=p; i++)
{
if(p%i==0)
c++;
}
if(c>2)
return 1;
else
return 0;
}
void fill()
{
int j=0;
if(m>0 && m<=20 && n>0 && n<=20)
{
arr[] = new int[m,n];
for(int i=0; i<m; i++)
{
j = 0;
while(j<n)
{
for(int k=1; k<=9999; k++)
{
int flag = obj.iscomposite(k);
if(flag ==1)
{
arr[j][i] = k;
j++;
}
}
}
}
}
else
{
System.out.println("The array cannot be created");
System.exit(0);
}
}
void display()
{
for(int i=0; i<m; i++)
{
for(int j=0; j<n; j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of rows maximum 20");
int a = sc.nextInt();
System.out.println("Enter the number of columns maximum 20");
int b = sc.nextInt();
p obj = new obj(a,b);
obj.fill();
obj.display();
}
}

You might also like