• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

find twin primes

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 114
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic