Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


Abhishek Sisodia
Prime Numbers
1 Answer(s)      5 years and 5 months ago
Posted in : IDE Questions



Advertisement
View Answers

April 21, 2009 at 4:22 PM


Hi Friend,

Use the following code:

class PrimeNumbers{
public static void main (String args[]){
String primeNo = "";
int counter = 0;
System.out.println("Prime Numbers are:" );
for (int i = 1; i < 120; i++){ {
int j;
for (j = 2; j < i; j++)
{
if (i % j == 0) {
break;
}
}
if (i == j) {
primeNo += i + " ";
counter++;
if (counter == 10) {
primeNo += "\n";
counter = 0;
}
}
}
}
System.out.println(primeNo);
}
}
Thanks


Related Tutorials/Questions & Answers:
 

 

 

DMCA.com