code not giving output
please help out with this code. Its compiling but giving no output:
/**
* this programme finds the no of prime nos <=n using seive of eratosthenes
*/
import java.io.*;
import java.util.*;
public class seive_of_eratosthenes
{
int a[][]=new int[50][10];
seive_of_eratosthenes()
{
for(int i=0;i<50;i++)
{
for(int j=0;j<10;j++)
{
a[i][j]=0;
}
}
}
public void main()throws IOException
{
int n,count=0,l=0,row=0,col=0;
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the no. upto which you want to find the prime number: ");
n=Integer.parseInt(b.readLine());
System.out.println("");
l=(n/10)+1; // stores the num of rows ocupied
for(int i=0;i<l;i++)
{
for(int j=0;j<10;j++)
{
while((10*i+j+1)<=n)
{
a[i][j]=10*i+j+1;
}
}
}
System.out.println("The resulting array is: ");
for(int e=0;e<l;e++)
{
for(int r=0;r<10;r++)
{
System.out.print(a[e][r]+"\t");
}
System.out.println("");
}
int k=(int)Math.sqrt(n); // gives the value of root of n
for(int i1=0;i1<l;i1++)
{
for(int j1=0;j1<10;j1++)
{
if(k<=a[i1][j1])
{
row=i1+1;
col=j1+1;
break;
}
}
}
for(int x=0;x<row;x++)
{
for(int y=0;y<col;y++)
{
for(int i2=0;i2<l;i2++)
{
for(int j2=0;j2<10;j2++)
{
if(a[i2][j2]%a[x][y]==0)
{
a[i2][j2]/=a[x][y];
}
}
}
}
}
for(int ii=0;ii<l;ii++)
{
for(int jj=0;jj<10;jj++)
{
if(a[ii][jj]!=(10*(ii)+(jj)+1))
{
a[ii][jj]=0;
}
}
}
a[0][0]=0;
for(int q=0;q<l;q++)
{
for(int w=0;w<10;w++)
{
if(a[q][w]!=0)
{
count=count+1;
}
}
}
System.out.println("The total number of prime nos upto "+n+" is/are "+count);
System.out.println("----------------------------------------------------------------------");
}
}
|