Java Creating a Prime Sieve with Boolean Expressions

  • Thread starter Thread starter JasonRox
  • Start date Start date
  • Tags Tags
    Expressions Prime
AI Thread Summary
The discussion revolves around creating a prime sieve using boolean expressions. The user recalls a method from Visual Basic involving the initialization of a series of boolean variables to classify numbers as prime or not. They seek guidance on how to create a large array of boolean variables, specifically using a syntax similar to p(i) where i ranges from 0 to X, with X determining the array size. The user provides an example of how to set specific indices to false, indicating non-prime numbers. A solution is provided, suggesting the creation of a boolean array in Java with the syntax "boolean [] p = new boolean[X];" where X can be set to any desired size, such as 1000. The user expresses gratitude and plans to implement the solution.
JasonRox
Homework Helper
Gold Member
Messages
2,381
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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
8
Views
2K
Replies
4
Views
10K
Replies
3
Views
4K
Replies
1
Views
2K
Replies
5
Views
2K
Replies
12
Views
2K
Back
Top