Contents
How do you print even and odd numbers?
Java Program to print Odd and Even Numbers from an Array
- public class OddEvenInArrayExample{
- public static void main(String args[]){
- int a[]={1,2,5,6,3,2};
- System.out.println(“Odd Numbers:”);
- for(int i=0;i
- if(a[i]%2!=0){
- System.out.println(a[i]);
- }
How do I print alternate even numbers?
AlternatePrimeNumberExample1.java
- public class AlternatePrimeNumberExample1.
- {
- //main method.
- public static void main(String[] args)
- {
- int num = 20;
- //prints alternate prime numbers.
- System.out.print(“Alternate prime numbers up to ” + num+” are: “);
How do you find a number is odd or even in C?
Enter an integer: -7 -7 is odd. In the program, the integer entered by the user is stored in the variable num . Then, whether num is perfectly divisible by 2 or not is checked using the modulus % operator. If the number is perfectly divisible by 2 , test expression number%2 == 0 evaluates to 1 (true).
How do I print odd numbers?
To print the odd numbers in C
- #include
- #include
- int i,n;
- printf(“\nENTER A NUMBER: “);
- scanf(“%d”,&n);
- printf(“\nODD NUMBERS BETWEEN 1 AND %d ARE: \n”,n);
- for(i=1;i<=n;i+=2)
- {
What is my alternate number?
An alternate contact number can be the extension for an operator or for another user (such as a supervisor or coworker), or any other number where you or another person can be reached.
How do you find the sum of alternate odd numbers?
If N is an odd number then the sum of alternate sign of first N natural numbers are = (N + 1) / 2.
How to print even and odd numbers using two threads?
1. Introduction In this tutorial, we’re going to have a look at how we can print even and odd numbers using two threads. The goal is to print the numbers in order, while one thread only prints the even numbers and the other thread only prints the odd numbers.
How to print even numbers in increasing order?
If the counter is even in the Thread T1, then wait for the thread T2 to print that even number. Otherwise, print that odd number, increment the counter and notify to the Thread T2 using the function notify ().
How to print number using two threads in Java?
Once the threads are started and start executing run () method of their Runnable task, printEven () and printOdd () methods are called. There based on the boolean flag one of the thread goes into wait state and other prints the number and also notifies the other thread using notify () method.
What to do if the counter is odd in a thread?
If the counter is even in the Thread T1, then wait for the thread T2 to print that even number. Otherwise, print that odd number, increment the counter and notify to the Thread T2 using the function notify (). If the counter is odd in the Thread T2, then wait for the thread T1 to print that even number.