answersLogoWhite

0


Best Answer

public class BasicThreads {

public static void main(String[] args) {

Thread odd = new Thread (new NumberPrinter());

Thread even = new Thread(new NumberPrinter());

odd.start();

even.start();

}

}

class NumberPrinter implements Runnable {

private static boolean printEven;

@Override

public void run() {

int start = printEven ? 2 : 1;

String type = printEven ? "Even Printer " : "Odd Printer ";

printEven = !printEven;

for ( ; start < 20 ; start += 2) {

System.out.println(type + start);

try {

Thread.sleep(100);

}

catch (Exception ex){

}

}

}

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Java program Create two threads such that one of the thread print even numbers and another prints odd numbers up to a given range?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Write a program to create a maze?

this is to write or create


How do you create a program that can input 100 names using flowchart?

create a program that can input 100 names


What is thread in c language?

thread is not specific to C-language. Use wikipedia to find out what threads are, and use Posix Threads (or pthreadsfor short) to create multi-threaded programs in C


What are the main features of a compiler in C programming language?

A compiler is a comp. Program that transforms source code written in programming language into another comp. Language.the main reason to compile a program is to create an executable program...


Make a C programming that displays the first four perfect numbers?

create a program that iterates until it finds a perfect number, then store that perfect number into an array. Continue iterating until you find three more. Then, you have an array of four perfect numbers.

Related questions

What mean by multithreaded program?

A multithreaded program is one that has multiple threads in execution. They may execute parallel to one another or totally without relation to one another. In Java you can create multithreaded programs using Java threads.


What is main thread in java program?

the main thread is the first thread that creates when the JVM starts executing your program. All subsequent threads that you may create in your program would be child threads to the main thread. It is important to note that if the main thread exits, all other threads that were spawned by it will also get killed.


Can we create more than 2 threads for a single object in java?

yes , we can create more than 2 threads for an object provided if all threads are reading the object. It will create deadlock in case multiple threads are writing into same object, hence we should not create multiple in this case.


How do you write a program to print numbers to 50 except prime?

First, create a for loop from a,1 to 50. Inside of that create another for loop b,2 to a-1. If a/b=int(a/b) then you know it is not prime


What is weft in textiles mean?

Weft refers to the threads that run horizontally across the fabric during the weaving process. It is interlaced with the warp threads, which run vertically, to create the fabric structure. The weft threads are inserted over and under the warp threads to create different patterns and textures in the fabric.


In 2010 how do you go to superstar threads?

you go on create mode and then go to create a superstar and it shud be there.


What are the requirements of a spark plug?

it must have threads and create spark


What numbers can you create with with 0?

None. Unless this is a trick question where you create an eight by putting one zero on top of another.


How do you get to superstar threads in WWE svr 2011 ps3?

go to create modes or whatever it says,it should say threads somewere


What kind of Windows program should be used to create a word search?

The windows program(s) that can be used to create a word search on a computer would be WordPad, which is sometimes called Notepad. Another good program to use would be Microsoft Word.


How do you get on superstar threads in svr 2011 for ps2?

At the Main Menu go to Create Mode and then Create a superstar then start creating.


How weaving is done?

Weaving is done by intertwining threads or yarns together on a loom to create fabric. The process involves interlacing the vertical threads (warp) with the horizontal threads (weft) to create different patterns and designs. Different techniques like plain weave, twill weave, and satin weave are used to create a variety of textures and structures in the woven fabric.