File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes find twin primes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "find twin primes" Watch "find twin primes" New topic
Author

find twin primes

kiran kirankukmar
Greenhorn

Joined: Jun 09, 2011
Posts: 7
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

Joined: Oct 02, 2003
Posts: 11406
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Aashu Mahajan
Ranch Hand

Joined: May 27, 2011
Posts: 113

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

Joined: Oct 02, 2003
Posts: 11406
    
  16

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

Joined: May 27, 2011
Posts: 113

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

Joined: Aug 31, 2010
Posts: 394

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


OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
kiran kirankukmar
Greenhorn

Joined: Jun 09, 2011
Posts: 7
I didn't see the solution that Aashu Mahajan provide but noe I got the code...
Thanks guys for guiding me...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: find twin primes