Java tutorial
//package com.java2s; /* * Copyright (C) 2012 Joakim Persson, Daniel Augurell, Adrian Bjugard, Andreas Rolen * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * This method starts as two and then marks all the multiples of two as * false, and then continues and does the same thing for three, five etc. * * @param integers * An boolean array of numbers. * @return An boolean array with prime numbers marked as true and their * multiples as false. */ private static Boolean[] removeMultiples(Boolean[] integers) { Boolean[] prime = integers; int end = (int) Math.sqrt(prime.length); for (int i = 2; i <= end; i++) { for (int j = i + i; j < prime.length; j += i) { if (j % i == 0) { prime[j] = false; } } } return prime; } }