• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Identify all prime numbers between 100 and 200

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone!
I'm new user to the Java and I don't understand how to solve this:
What is the code for creating a program which isentify and output all primenumbers between 100 and 200?
Can anyone please help me?
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a prime is a number that yields an integer value when divided by any number other than itself (and 1).
In practice the test does not have to be run for numbers greater than the square root of the number being tested rounded up to the next whole number.
Also, only other prime numbers need to be taken into consideration (whether applying that is cheaper than a brute force approach is open for debate and implementation dependant).
As a result of the rules, you only need to test odd numbers and need to divide only by odd (prime) numbers smaller than the square root of the candidate prime under consideration.
By taking an array of odd numbers between 100 and 200 and iterating over that building an array of primes found you will get what you want.
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the code for creating a program which isentify and output all primenumbers between 100 and 200?
Are you in the same class with Linnea Palin? She already asked exactly same question here. The answer is, of course, that no one will do your homework for you, but we are willing to help you if you hit a wall.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a pretty standard assignment
That's why I give just the math behind it in words, let them figure it out for themselves (or slavishly copy it from any of a thousand books of course and hope their instructor hasn't read the same book).
 
Alexander Skagerling
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!
Thanks for answering but Maybe you can gice me some more hints???
 
Alexander Skagerling
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Jeroen Wenting:
It's a pretty standard assignment
That's why I give just the math behind it in words, let them figure it out for themselves (or slavishly copy it from any of a thousand books of course and hope their instructor hasn't read the same book).


Can you maybe give some examples of books, or site which canngive me the code for free? =)
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure. here is a web page which would be very helpful to you. Be sure to read the whole thing!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!