File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Java Program for Prime numbers Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

Java Program for Prime numbers

Brijesh Shah
Ranch Hand

Joined: Aug 08, 2006
Posts: 34
Hi All,

I have a program here:
/*Program to print prime numbers between 1 to n*/
while(i<=n-1)
{
if((n%i)==0)
{
break;
}
i++;
}
if(i==n)
{
System.out.println("The prime numbers between 1 and " +n+ " are:");
System.out.println(""+n);
}
n--;
}
}

Please help me why this code does not lead me to the end results???
This is a program to find out prime numbers between 1 to N
Thanks in advance....
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32675
    
    4
Please don't post the same thing twice. Ask one of the bartenders to move your original thread.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9948
    
    6

The other thread in JiG(I) has more discussion, so i'm going to close this thread. that is not to say that the other one won't be moved...


Never ascribe to malice that which can be adequately explained by stupidity.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Java Program for Prime numbers
 
Similar Threads
Display the prime factors of a number using sets
problem with java code
Java Prime Number Program
So just how MUCH must they know?
generating numbers from 1 to 100 to store in an array