aspose file tools*
The moose likes Beginning Java and the fly likes Thread and Pipes problem. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Thread and Pipes problem." Watch "Thread and Pipes problem." New topic
Author

Thread and Pipes problem.

kunagu varun
Ranch Hand

Joined: Apr 13, 2010
Posts: 38
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...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38393
    
  23
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.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11240
    
  16

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.


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

Joined: Apr 13, 2010
Posts: 38
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..
W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Posts: 710
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.


SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
kunagu varun
Ranch Hand

Joined: Apr 13, 2010
Posts: 38
Thanks for the link.. I will try as you suggested and post back here later..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread and Pipes problem.