i have problem in that program 1 Answer(s) 2 years and 8 months ago
Posted in : JavaMail
1. 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..
2. Develop a simple OPAC system for library using even-driven and concurrent programming paradigms of Java. Use JDBC to connect to a back-end database.
View Answers
September 9, 2010 at 4:39 PM
Hi Friend,
Try the following code:
import java.io.*; import java.util.*;
class MyThread1 extends Thread{ private PipedReader pr; private PipedWriter pw;
MyThread1(PipedReader pr, PipedWriter pw){ this.pr = pr; this.pw = pw; } public void run(){ try{ int i; for (i=1;i<10;i++){ int j; for(j=2; j<i; j++){ int n = i%j; if (n==0){ break; } } if(i == j){ pw.write(i+"\n"); } } pw.close(); } catch (IOException e) { } } } class MyThread2 extends Thread{ private PipedReader pr; private PipedWriter pw;
MyThread2(PipedReader pr, PipedWriter pw) { this.pr = pr; this.pw = pw; } public void run() { try { int f1, f2 = 1, f3 = 1; for (int i = 1; i <10; i++) { pw.write(f3+"\n"); f1 = f2; f2 = f3; f3 = f1 + f2; } pw.close(); } catch (IOException e) { } } } class MultithreadedProgram{ public static void main(String[] args) throws Exception { PipedWriter pw1 = new PipedWriter(); PipedReader pr1 = new PipedReader(pw1); MyThread1 mt1 = new MyThread1(pr1, pw1); System.out.println("Prime Numbers: "); mt1.start(); int item1; while ((item1 = pr1.read()) != -1){ char ch1=((char) item1); System.out.print(Character.toString(ch1)); } pr1.close(); PipedWriter pw2 = new PipedWriter(); PipedReader pr2 = new PipedReader(pw2); MyThread2 mt2 = new MyThread2(pr2, pw2); System.out.println("Fibonacci Numbers: "); mt2.start(); int item2; while ((item2 = pr2.read()) != -1){ char ch2=((char) item2); System.out.print(Character.toString(ch2)); } pr2.close();
} }
Hope that it will be helpful for you. Thanks
Related Pages:
i have problem in that program - JavaMail ihaveproblem in that program 1. Write a multi-threaded Java program to print all numbers below 100,000 that are both prime and fibonacci number... = pw;
}
public void run(){
try{
int i;
for (i=1;i<10;i
i have problem with classnofounderror ihaveproblem with classnofounderror import java.sql.*;
public class Tyagi
{
public static void main (String args[])throws SQLException
{
ResultSet rs;
try
{
Class.forName
i have problem with classnofounderror ihaveproblem with classnofounderror import java.sql.*;
public class Tyagi
{
public static void main (String args[])throws SQLException
{
ResultSet rs;
try
{
Class.forName
i have a problem in spring - Spring ihave a problem in spring spring Aop: how to configure proxyfactorybean in xml file for providing advices for one particular class
I have problem in my Project Ihaveproblem in my Project Dear Sir,
ihaveproblem in my project about Jtable
ihave EDIT JButton whenevery i was click on edit he is display all data from database but i want to select any row
problem i coding problemi coding ihave a problem in coding a combobox containing a number of *.java program on click one of them that program should compile and run and display the result in other window
i have a problem to do this question...pls help me.. ihave a problem to do this question...pls help me.. Write a program... reversedNumber = 0;
for (int i = 0; i <= num; i...;
reversedNumber = reversedNumber * 10 + r;
i = 0
problem in servlet program problem in servlet program Dear Sir, Ihave a problem to insert the Blob type data like as video file, audio file in the database using Servlet and html code
I have need to help Ihave need to help Write a program that, for four points A, B, C and P, draws a triangle formed by ABC
and a small cross showing the position of P; and displays a line of text indicating which of
the following three cases
Java program problem
Java program problem Hi,
I took the chance to login here in your.... Please help me. I provided below the program assignment. Thanks in advance.
Create program that:
Will search through two directory structures and
produce
Java I/O problem
Java I/O problem
Write a Java application that prompts the user.... The program should use the FileWriter class and an appropriate processing stream... by line, and output it to the console with the line number. The program should
I have a doubt regarding action - Struts Ihave a doubt regarding action hi,
Ihave doubt regarding struts,I got response through jsp and once again it redirecting to action...,
Please check Action Mapping in the struts-config.xml. If you have any problem
problem in coding problem in coding ihave a following code which display the contents of the text file but not other program like java or any c program is there any handler to open the program files other than Filereader.
FileReader fr = new
Problem in running first hibernate program.... - Hibernate Problem in running first hibernate program.... Hi...I am using... programs.It worked fine.To run a hibernate sample program,I followed the tutorial below...();
session.close();
}
}
}
Thanks Ihave changed
how do i solve this problem?
how do i solve this problem? Define a class named Circle with the following properties:
List item
An integer data field named radius... another class named TestCircle to test the Circle program by creating two Circle
connectivity problem
: oracle.jdbc.OracleDriver""
i am using this with netbeans since ihave gain connectivity still i am facing this error*
================================oracle...connectivity problem i am facing error in Class.for name statement
jdbc problem
jdbc problem hi my name is mohit...i am making a project in java.......ihave made this code in netbeans...ihave already entered the values......the user inputs the username and password and then i want to match the username
result problem
result problem sir,ihave written program given below but that program is not giving proper output.pls help me
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
class filedata extends
programming problem
. He has also decided a few rules for the division of islands:
i) Eric and Finn... as you like, but you have limited resources.
Your advisers tell you that, if you....
Although you have doubts about their advice you decide to go ahead
I have crude application Ihave crude application Ihave crude application, how to load into this roseindia.net
write program have product - using loops
write programhave product - using loops Write a program...), name (String) and price (double).
Your program should continue reading new...(list3);
double sum=0;
for(int i=0;i<list3.size();i++){
sum
servlet program problem - Java Beginners
servlet program problem
i used ur servlet example prg with xml file of helloworld program and i run dat program in tomcat, it shows only the files in my specified directory but when i clicked dat file name it just displaying
I/O Program output error I/O Program output error Hello All,
I am working on a program... file, but I am getting incorrect output. Ihave been successfull with part of the program in that it reads the text file and analyzes it, however I need it to take
Can I have multiple main() methods in the same class?
Can Ihave multiple main() methods in the same class? Hi,
Can Ihave multiple main() methods in the same class?
Hi,
No, We cann't use multiple main() method within the same class. If we do this then the program
Still have the same problem--First Example of Struts2 - Struts
Still have the same problem--First Example of Struts2 Hi
I tried the example in the link. But still I am getting the same problem like as I... the current time.
I also tried the directory structure mentioned in the above link
which tag i have to use - Java Server Faces Questions
which tag ihave to use Hi All,
Ihave one Question Regadding Jsf.
when i clicked on one dropdown list box.when i select one item it should....
for that what tag ihave to use.please help me.
Thanks,
Puppy. use
Programming: Hammurabi I - Solution
Java NotesProgramming: Hammurabi I - Solution
Solution
The following two source files are a solution to the
Hammurabi I programming problem.
This solution has expanded somewhat on the minimum requirements.
Main program
1
2
I face some problem - Java Beginners I face some problem I face some problem in my project plz deepak halp me how can i solve this problemi m using bean and jsp file also. and deployee the using tomcat server
plz help me how can i solve thisproblem
HTTP Status
program
the College class and invoke the method.
hi dhivya,
Here I am giving an example of your problem.
public class College
{
String str = "IIT
sir i,have a assignment for these question plz help me sir - JavaMail
sir i,have a assignment for these question plz help me sir  ... class hierarchy in Java. Write a test program to demonstrate polymorphism
 ...;
} else {
String str = " ";
for (int i = 0; i <= top; i++)
str
Program
is then calculated. For this application, we have created a table test...=conn.createStatement();
ResultSet rs=st.executeQuery("select * from test");
int i=0...;
<td><input type="radio" name="radio<%=i%>" value="<
hello there i need help
transaction?
thats the problem. I dont know how to start this program because...hello there i need help : i need to do a program like... OPtions:
once ihave chosen an option then i should proceed here
if i choose b
File I/O
File I/O i am trying to write a program that reads a text file... the text file then read it and write it into as a comma delimitade file. ihave to problem:
everything is perfect but when it comes to writing my program also
File I/O
File I/O greetings i was running into a problem. is their a way... c: drive ihave tried writing to a different directory but i cant
 ...();
File[] files = file.listFiles(filter);
for (int i = 0; i <
I/O Java I/O Java import java.io.File;
import java.io.FileNotFoundException... a RuntimeException if any problem occurs in
// opening the inputFile
// The copy... writer = new PrintWriter(outFile);
for(int i=0;i<inputFiles.length;i
File I/O
File I/O ihave a problemi am trying to print on a new line every time i reach a certain condition "if(line.startsWith("Creating"))" i want...
this is my code
package elite.tech.com;
/***********
* program Cvs
code problem - Java Beginners
code problem Dear sir,
my problem is that, ihave two Combobox
one... then another combobox should have been mumbai and dellhi value and when america is selelcted then another combobox should have washingtone and newyork value
I have doubt in jsp file. Ihave doubt in jsp file. Ihave doubt in jsp file.
In a jsp file, there should be two buttons. One is start and other is stop.
When we click on start then only stop should be enabled. Other wise it should be disabled.
When