• 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 127th twin-prime pair?

 
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
source - chetanasforum (a Job Portal site)
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.
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
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
Thanks Stephan van Hulst
I understood now but found it difficult to code. Could you please code it, i tried many with many loop but failed.
 
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
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.
 
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
Hello guys, After so many tries i think i came to near it, Here i need your help.

Output :

But the output should be (2,5) (5,7) (11,13) (17,19)
Please correct me where i am wrong??
>
 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
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
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).
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stephan already told you what to do...

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.



 
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

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).
 
Aashu Mahajan
Ranch Hand
Posts: 114
Eclipse IDE Oracle Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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




 
Greenhorn
Posts: 7
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

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.

 
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
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?
 
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
kiran kirankukmar,
Your post was moved to a new topic.
 
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
thanks
 
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
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sir please include if statement of k<100 before that storing prime numbers in array..
 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aashu, I checked for you, your answer is correct.
 
author
Posts: 9050
21
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

For anyone reading this thread, don't worry, there's nothing like this on the real exam.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

 
prasad surisetti
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

 
Aashu Mahajan
Ranch Hand
Posts: 114
Eclipse IDE Oracle Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello prasad surisetti,
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

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic