• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

find twin primes

 
kiran kirankukmar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sir
i read that above topics and trying to solve those but i am finding difficulty in that and it is not getting.
i already done of generating prime numbers between 1 to 1000 but finding of twin pairs getting difficulty.
please help in that finding pair sir..
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12100
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I said elsewhere, show us what you've done. Post your code (and please use the 'code tags' to make it easier to read).

but generally, if you have found the first 1000 primes, hopefully you have them in an array. If so, all you need to do is loop through the array, and look at the i'th an i'th + 1 elements. See if the difference between them is 2 or not. If so, they are a twin pair. if not, they aren't.
 
Aashu Mahajan
Ranch Hand
Posts: 114
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello kiran kirankukmar, There was some silly syntax error you made while writing code but your concept was very near to correct. I have correct your code here :
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12100
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please resist the temptation to provide solutions like this.

If someone is trying to learn to be a cook, it it better to hand them a fully decorated cake, or to have them spend time in the kitchen baking and decorating it themselves, providing tips when they need/ask for it?
 
Aashu Mahajan
Ranch Hand
Posts: 114
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi fred rosenberger
I didn't mean to provide solution, i just rectified the error that kiran have made while writing their code in another similar thread.
well all is good now and i did solve it differently than Kiran.
Finally the problem resolved

@Kiran
your concept is correct but should take care about syntax error and blocks.
if you still have any problem write here.
 
Ikpefua Jacob-Obinyan
Ranch Hand
Posts: 394
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys... Fred has said it all where are the codes?...The best way to resolve doubts -at least in java- is to see 'codes-in-action' and resolve the problem with the codes you see...We all have tons of logics in our brains to argue...Without codes you spend more time and brain energy.

Regards

Ikpefua
 
kiran kirankukmar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't see the solution that Aashu Mahajan provide but noe I got the code...
Thanks guys for guiding me...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic