【发布时间】:2010-07-25 00:00:04
【问题描述】:
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吗?我觉得这里比较合适。