Java Program to Print Even Odd Using Two Threads in17 Mar 2025 | 4 min read Thread is a part of multithreading programming. In order to write a code for printing even and odd using 2 threads, it is required that we should have knowledge of multithreading. Now, we need to print the even and odd numbers in natural order up to MAX using two different threads. So, we have two ways to solve the problem, i.e., by using wait and notify and by using the concept of the remainder. By Using wait and notifyIn order to print the even and odd numbers using wait and notify, we use the following steps:
Let's implement the code for printing the even odd numbers using wait and notify. PrintEvenOddExample1.java Output: ![]() By Using RemainderIn this technique of printing even and odd numbers with two threads, the code is based on the following two points:
EvenOddRunnable.java PrintEvenOddExample2.java Output: ![]() Next TopicJava Variant |
Working with JAR and Manifest files In Java
Java Archive (JAR) files are a common way to package and distribute Java applications. A JAR file is a compressed file format that contains Java class files, resources (such as images and properties files), and metadata. It simplifies the distribution of Java applications by bundling everything...
5 min read
ChoiceFormat getFormats() method in Java with Examples
The java.text.ChoiceFormat is a class containing a getFormats() as a function. When the ChoiceFormat object is being initialized, the ChoiceFormat class is utilized to retrieve the connected format. It provides an array of the specified type. Syntax: public Object[] getFormats() Parameter: There are no parameters accepted by this...
2 min read
compareToIgnoreCase Java
In Java, the method compareToIgnoreCase() belongs to the String class that belong to java.lang package. It is used for comparing any two strings by ignoring the lower- and upper-case differences. The method does the comparison of strings using the Unicode value of each character present in...
5 min read
What is Advance Java
? The dictionary meaning of advance is a forward movement or a development or improvement and the meaning of improve means thing that makes something better. All in all, we have to improve our basic knowledge to master in that particular field. Java is divided into two parts...
15 min read
Input from console in Java
Reading data from keyboard There are many ways to read data from the keyboard. For example: InputStreamReader Console Scanner DataInputStream etc. InputStreamReader class InputStreamReader class can be used to read data from keyboard.It performs two tasks: connects to input stream of keyboard converts the byte-oriented stream into character-oriented stream BufferedReader class BufferedReader class can be used...
1 min read
Convert IP to Binary in Java
In computers, fundamental conversion (like decimal to binary or vice-versa) is an important task. In networking, it is important to understand IP addressing and subnetting. IP addressing is the main functionality of networking. For a network engineer, assigning IP addresses, determining the network or host ID...
3 min read
Difference Between System.out.print() and System.out.println() Function in Java
In Java, System.out.print() and System.out.println() are two methods defined in the System class to send output to the console. They look and sound similar, but they behave differently in terms of cursor movement and formatting of the output. Java System.out.print() Method The System.out.print() method prints the specified...
3 min read
Recursive Binary Search in Java
The binary search algorithm is one of the commonly used algorithms in programming. It is used to search and find an element in a sorted array. The binary search algorithm is a highly efficient search technique used to locate a specific element in a sorted dataset. It...
5 min read
Ladder Pattern in Java
In the ious sections, we have discussed many pattern programs. In this section, we will create Java program to print ladder with n steps. Using for Loop The following program prints the ladder with the gap between two side rails being 3 spaces. LadderPatternExample1.java import java.util.Scanner; public class LadderPatternExample1 { public static void...
2 min read
Sylvester's Sequence in Java
Sylvester's sequence is a mathematical sequence where each term is derived from the product of all ious terms plus one. It starts with 2, and subsequent terms grow rapidly. This sequence has applications in number theory and combinatorics. Implementing it in Java involves recursive or iterative...
8 min read
We request you to subscribe our newsletter for upcoming updates.

We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India

