Java How to Program
Takes a new tools-based approach to Web application development that uses Netbeans 5.5 and Java Studio Creator 2 to create and consume Web Services. Features new AJAX-enabled, Web applications built with JavaServer Faces (JSF), Java Studio Creator 2 and the Java Blueprints AJAX Components. Includes new topics throughout, such as JDBC 4, SwingWorker for multithreaded GUIs, GroupLayout, Java Desktop Integration Components (JDIC), and much more.
/**
* @author Shri Krishan Yadav
* This program find and displays prime numbers between 1 and a given number.
* It doesn't include the number entered.
*/
public class PrimeNumbers {
/**
* @param args
*/
public static void main(String[] args) {
if(args.length==0)
{
System.out.print("Please ennter a Number.");
System.exit(0);
}
int count=0;
int number= Integer.parseInt(args[0]);
int[] numColl= new int[number];
for (int i=1;i<number;i++)
{
if(i==1)
{
continue;
}
else if(i==2||i==3||i==5||i==7)
{
count++;
numColl[i]= i;
continue;
}
else
{
if(i%2==0||i%3==0||i%5==0||i%7==0)
continue;
else
{
numColl[i]= i;
count++;
continue;
}
}
}
Arrays.sort(numColl);
System.out.println("Prime numbers between 1 and "+number+" are "+ count);
int N=1;
for(int i=0;i<numColl.length;i++)
{
if(numColl[i]==0)
continue;
else
{
System.out.println("Prime number " +N+ " is: "+numColl[i]);
N++;
}
}
}
Thanks works great!
This works great but I need one that uses arrays. Thanks anyway
This might help!!
/** * */ package main; import java.util.Arrays;
/** * @author Shri Krishan Yadav * This program find and displays prime numbers between 1 and a given number. * It doesn't include the number entered. */ public class PrimeNumbers {
}