The Artima Developer Community
Sponsored Link

Java Answers Forum
Prime Numbers

2 replies on 1 page. Most recent reply: Feb 22, 2003 8:07 PM by Charles Bell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
sean foley

Posts: 1
Nickname: foley
Registered: Feb, 2003

Prime Numbers Posted: Feb 18, 2003 12:08 PM
Reply to this message Reply
Advertisement
Having difficulties with the following program,would value some inspiration from someone,

"program that prints all prime numbers between 1 and 1000 inclusive."

need an inner for loop nested inside an outer for loop. The outer for loop will loop through all the numbers from 1 to 1000 for you and for each iteration of this outer loop the inner one will then loop through all the possible divisors from 1 to that value and if a divisor is found to divide in exactly then the number of times this number has been divided exactly increases by 1 for each such divisor.

Sean.


deliquentMind

Posts: 3
Nickname: deliquent
Registered: Feb, 2003

Re: Prime Numbers Posted: Feb 21, 2003 5:24 AM
Reply to this message Reply
try to code this:


1: print "Enter start range"
2: read start
3: check the end range, it should be greater than start, otherwise
inform the user to enter again
4: set correctInput equal to false
5: while (correctInput equal to false)
6: begin
7: print "Enter end range : "
8: read end;
9: if (end > start)
10: set correctInput equal to true
11: end_if
12: end
13: set counter equal to start
14: while (counter less than or equal to end)
15: begin
16: set limit equal to square root of counter
17: set denum equal to 2
18: set isPrime equal to true
19: while (denum is less than or equal to limit)
20: begin
21: if (counter modulos denum equal to zero)
22: set isPrime equal to false
23: end_if
24: increment denum by 1;
25: end_while
26: if (isPrime)
27: print(counter)
28: increment counter by 1
29: end_while

Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: Prime Numbers Posted: Feb 22, 2003 8:07 PM
Reply to this message Reply
Check this link:
http://www.quantumhyperspace.com/SourceBank/viewCode.jsp?javaFile=PrimeNumberGenerator.java

Flat View: This topic has 2 replies on 1 page
Topic: RMI Excute problem Previous Topic   Next Topic Topic: Java Mail from iPlanet

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use