# Find 127th twin-prime pair?

Find 127th twin-prime pair(For more information on what is twin prime, look at Wikipedia)

Please could anybody tell me to code this program in java??

I actually could not understand what is twin-prime pair??

Please clear my doubts.

What you can do is generate prime numbers, and subtract each new prime number by the number you generated before that. If the result is two, then the two numbers are a twin prime pair.

*The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.*

Show us what you've tried, ask specific questions, tell us what exactly isn't working, and you'll get tons of help, but nobody here will (or should) provide you with the solution.

If they do, and I see it, I will delete it.

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

Hint: a number x is prime if there are no other prime numbers that divide it. So it may be useful to keep track of the prime numbers you've generated so far.

*The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.*

In ANY programming problem, you break down what you are trying to do into simpler pieces. In this case, the two main things you need to do are:

a) Find prime numbers

b) given a list of prime numbers, print out twin primes.

Both are COMPLETELY independent of each other. I don't have to know anything about twin primes to generate a list of primes. Further, if someone was handing me a list of primes, I don't care HOW it was generated, I just need to look for the twins in that list.

So...to start, write a method that will generate a list of primes. I would write it so that I could give it an upper limit - i.e. only generate 100 primes to start. Stephan's suggestion was to keep track of all the ones you find, and use those to test for the next one.

Aashu Mahajan wrote:Please guys help me, i already spent more than 2hr on this code to get output according to given question Please what else i can do in existing code to show the ouput like (2,5) (5,7) (11,13) (17, 19).

also...(2,5) is wrong...it should be (3,5).

- 1

Thanks to fred rosenberger, Stephan van Hulst for you suggetion

First of all i constrcut an array of int of length 100 and then i made a method that generate prime no. Now when the method is called is it would generate a prime no. series and this those prime series are stored in array then after the problem get very clear. I happy now

- 1

Aashu Mahajan wrote:Hey Guys Finally i did it, i did it, i solved this problem

Thanks to fred rosenberger, Stephan van Hulst for you suggetion

First of all i constrcut an array of int of length 100 and then i made a method that generate prime no. Now when the method is called is it would generate a prime no. series and this those prime series are stored in array then after the problem get very clear. I happy now

Hi friend..congrats for that code.I am trying from 2hrs but i cant getting a single error make me confusion.please mail your code to me once i will see and correct my code please...please....

my mail id is kirankiran123456.kk@gmail.com.

please mail me...

kiran kirankukmar wrote:

Hi friend..congrats for that code.I am trying from 2hrs but i cant getting a single error make me confusion.please mail your code to me once i will see and correct my code please...please....

my mail id is kirankiran123456.kk@gmail.com.

please mail me...

Kiran,

Please read my earlier posts. We don't hand out code here as 'ready-made solutions'. We try to help people learn how to write code for themselves.

If you need help, I would suggest you start your own thread/topic, post what code you have, and ask specific questions there. Folks here love to help, but nobody can or should do your work for you.

My answere is :

127th twin-prime pair is : (5009, 5011)

@kiran kirankukmar

The problem is somewhat tricky and fred rosenberger, Stephan van Hulst explained well, read their each words carefully. you will get hint.

@fred rosenberger, Stephan van Hulst

I want you check my code weather my answer is correct or not. and what should be the answere according to you?

Your post was moved to a new topic.

Sheriff

Prasad babu wrote:source - chetanasforum (a Job Portal site)

Find 127th twin-prime pair(For more information on what is twin prime, look at Wikipedia)

I just write the code for this yar if you want that source code contact me on spb.1986@gmail.com.

hey this is prasad. i just write the code for this. if you want that contact me on spb.1986@gmail.com k

- 1

Welcome to Java Ranch

I already solved this question 1day ago, read my posts again and please don't provide email address here but yes you can tell the logic(not full coding) you applied because Every problem has a no. of solutions(especially in Java Programming ) so i would appreciate you share the logic applied to make the code successful. Also you can not get the coding of this program even searching on google.

Thanks

Keep stay with Java Ranch