Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Prime Number Program

807591Apr 3 2005 — edited Apr 30 2008
I am trying to construct a program that lists out all the prime numbers between 1 and 100 but I am having an extremely difficult time with it, here is what i want to be printed out:

PRIMES BETWEEN 1 AND 100

2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

this is all I have right now...I've tweaked with it a lot and I havent been able to come up with anything successful so here's the basic outline in original form

I'm fairly new to java so if for loops and while loops were used it would make more sense to me....I am also familiar with modulo, which I think would be a good tool for this program, right?

any help you guys give me is really appreciated

thanks
public static void main(String args[]) throws IOException
	{
		System.out.println("Prime Numbers from 1 to 100");
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); 
		System.out.print("Enter the primes upper bound  ===>>  ");
		final int MAX = Integer.parseInt(input.readLine());
		boolean primes[] = new boolean[MAX];
		computePrimes(primes);
		displayPrimes(primes);
	}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 28 2008
Added on Apr 3 2005
26 comments
942 views