Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args)
- {
- boolean[] test = sieve(createSequence(15));
- for (int index = 0; index < test.length; index++)
- if (test[index] = true)
- System.out.print("T");
- }
- public static boolean[] createSequence(int input)
- {
- int i = 2;
- boolean[] numArray = new boolean[input-1];
- for(int index=0; i <input+1; index++)
- {
- numArray[index] = true;
- i++;
- }
- return numArray;
- }
- public static boolean[] crossOutHigherMultiples(int i, boolean[] sequence)
- {
- for (int index = 2; index*i <= sequence.length+1; index++)
- sequence[(index*i)-2] = false;
- return sequence;
- }
- public static boolean[] sieve(boolean[] sequence)
- {
- for (int index = 2; sequence[index] = true && index > Math.sqrt(sequence.length); index++)
- {
- sequence = crossOutHigherMultiples(index, sequence);
- }
- return sequence;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement