Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Prime Number  RSS feed

 
ken john
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any idea how to write a program to print all the prime numbers within 10000 which has three “7” digits. Examples: 1777

Class java() {

public static void main(String arg[]) {

......

Please help!
 
Mohamed Sanaulla
Bartender
Posts: 3179
34
Google App Engine Java Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you trying to implement it in Java? From the few lines of code you have provided- I assume you are not familiar with Java. If its a homework question please DoYourOwnHomework , and you cannot expect anyone here to just give you the program for the same.

The steps which I can think of-
- Find the prime numbers within 10000- You can get the algorithm for this from a lot of places or you can write one yourself.
- Now to find out if there are three 7's you can either- Convert the number into a string and find if it has three 7's or you can find individual digits in the number and see if it has three 7's. Again for the second method there's a standard approach and you can find this algorithm in programs that deal with reversing a number.

So once you have some code and not able to proceed further do let us know and we will help you out.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or you could generate every possible number with three sevens, then test to see if each is prime. I think there are only 40.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!