Twin prime pairs are two prime numbers that have a difference of two. Have you read the Wikipedia page? It's pretty clear.

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.

We don't do that here. Handing out a solution does nobody any good.

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

Aashu, don't worry about the pairs yet. Start by writing a program that prints a list of prime numbers.

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.

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).

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).

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

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.

Hello Guys,
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?

I can tell by looking at it your code won't compile. Also, PLEASE move this discussion to YOUR thread that I created for you (linked to above), rather than continuing to hijack this thread.

kiran kirankukmar
Greenhorn

Joined: Jun 09, 2011
Posts: 7

posted

0

sir please include if statement of k<100 before that storing prime numbers in array..

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

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.