Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 30th, 2014, 06:01 AM
Registered User
 
Join Date: May 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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("----------------------------------------------------------------------");
}
}
 
Old December 6th, 2014, 03:56 AM
Registered User
 
Join Date: Dec 2014
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Are there errors like this? Try posting the full stack trace...





Similar Threads
Thread Thread Starter Forum Replies Last Post
C# code is giving errors hlynnerup BOOK: Professional DotNetNuke Module Programming ISBN: 978-0-470-17116-5 0 April 28th, 2010 12:38 PM
Help me by giving code for this search button csateesh ASP.NET 1.0 and 1.1 Professional 1 August 7th, 2007 07:40 AM
Please help my code is not giving me a result set yudee JSP Basics 0 September 20th, 2006 09:55 AM
This piece of code is giving an error sourik C# 2 July 15th, 2006 09:18 AM
This piece of code is giving an error sourik Classic ASP Databases 1 July 14th, 2006 09:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.