• 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

Thread and Pipes problem.

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Write a multi-threaded Java program to print all numbers below 100,000 that are both prime and fibonacci number (some examples are 2, 3, 5, 13, etc.). Design a thread that generates prime numbers below 100,000 and writes them into a pipe. Design another thread that generates fibonacci numbers and writes them to another pipe. The main thread should read both the pipes to identify numbers common to both.

Hello ranchers please give an idea of how to implement above problem...
 
Marshal
Posts: 79401
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need a program which finds Fibonacci numbers and one to find prime numbers.

Really! You didn't think we would produce your code or do your homework, did you?

You will have to show us what you have got already, and we'll tell you what we think of it.
 
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
start small. write a little code at a time. Every time I start a new program, I write exactly this much before I compile and test:


Once I'm sure that compiles and runs, I'll add a few more lines. Then I'd compile, test and debug those few lines.
 
kunagu varun
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I feel sorry for my irregular post ranchers...
I have gathered some information regarding pipedIO and written the following code for my problem stated in the previous post..

Please have a look at this code..


The following is the output which i am getting..
0
1
1
2
2
3
3
5
5
7
8
13
21
34
55
89
144
233
377
610
987
1597
0
1
2
3
1
2
3
5
8
13
Terminated
5
7
21
34
55
89
144
233
377
610
987
1597
0
1
1
2

Please solve this issue..
 
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To me it looks like you are getting complicated when you don't need to. I thought this was an interesting problem, so I coded it earlier to see what I came up, after some research. I'd suggest making 3 classes: 1 that does the fibonacci numbers, one that figures the primes, and a third that will be used to compare the two. After you get those three classes functional, then I would look into integrating threads and pipes.

I suggest looking at this link, and the programs they designed.
 
kunagu varun
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the link.. I will try as you suggested and post back here later..
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic