Creating a Prime Sieve with Boolean Expressions

  • Context: Java 
  • Thread starter Thread starter JasonRox
  • Start date Start date
  • Tags Tags
    Expressions Prime
Click For Summary
SUMMARY

This discussion focuses on creating a prime sieve using boolean expressions in programming. The user seeks guidance on initializing a large array of boolean variables to classify numbers as prime or non-prime. The solution provided involves declaring an integer variable X to define the size of the boolean array, followed by initializing it with the syntax boolean [] p = new boolean[X];. This approach allows for efficient classification of numbers in the sieve algorithm.

PREREQUISITES
  • Understanding of boolean data types in programming
  • Familiarity with array initialization in Java
  • Basic knowledge of prime number algorithms
  • Experience with loops and conditional statements in programming
NEXT STEPS
  • Implement the Sieve of Eratosthenes algorithm in Java
  • Explore optimization techniques for prime number generation
  • Learn about memory management in large arrays
  • Investigate alternative data structures for prime sieving
USEFUL FOR

Programmers, computer science students, and anyone interested in algorithm optimization and number theory will benefit from this discussion.

JasonRox
Homework Helper
Gold Member
Messages
2,394
Reaction score
4
I'm trying to create a sieve (prime sieve). A nice quick simple one using boolean expressions.

I remember on Visual Basics it began by creating like X number of boolean variables and then sieve them out by classifying them as false... and so on.

How to a create a large group of boolean variables?

I think it was something like p(i) and i=X, which X determined how many to create. It was something like this I think.

So, technically i is like a variable itselt because when I go through the loop, I should be able to go through steps like...

p(4) = false;
p(6) = false;
p(8) = false;

... all the way until I reach 2X.

So, how do you create this variable?

Thanks, I appreciate it.
 
Technology news on Phys.org
Create as big of an array as you like.

int X = 1000 ;

boolean [] p = new boolean[X];
 
Thanks a lot.

I'll see how it turns out.
 

Similar threads

Replies
4
Views
4K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 4 ·
Replies
4
Views
10K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
12
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K