home | career | drupal | java | mac | mysql | perl | scala | uml | unix

Groovy example source code file (sieve.java)

This example Groovy source code file (sieve.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

count, count, num, num

The Groovy sieve.java source code

// $Id: sieve.java,v 1.1 2004-05-23 07:14:28 bfulgham Exp $
// http://www.bagley.org/~doug/shootout/

public class sieve {
    public static void main(String args[]) {
	int NUM = Integer.parseInt(args[0]);
	boolean [] flags = new boolean[8192 + 1];
	int count = 0;
	while (NUM-- > 0) {
	    count = 0;
	    for (int i=2; i <= 8192; i++) {
		flags[i] = true;
	    }
	    for (int i=2; i <= 8192; i++) {
		if (flags[i]) {
		    // remove all multiples of prime: i
		    for (int k=i+i; k <= 8192; k+=i) {
			flags[k] = false;
		    }
		    count++;
		}
	    }
	}  
	System.out.print("Count: " + count + "\n");
    }
}

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy sieve.java source code file:

new blog posts

 

Copyright 1998-2014 Alvin Alexander, alvinalexander.com
All Rights Reserved.