1
package Algorithms;
import cs1.Keyboard;
import java.util.*;
public class SieveofEratosthenes2 {
public static void main (String[] args){
//input number and create an array with the length of (num-1)
int num = Keyboard.readInt();
ArrayList prime = new ArrayList(num);
//populate array with all numbers from 2 to num
for(int i = 0; i < prime.size()-1; i++)
{
Integer temp = new Integer(i+2);
prime.add(i, temp);
}
System.out.println(prime.size());
你會考慮使用'int []'而不是'ArrayList'嗎?我認爲這裏適合。 – 2010-07-25 00:24:29