- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java program to Print Odd and Even Number from an Array
In the loop check, the result of I %2 operation on each element, if 0 the element is even else the element is odd.
Example
public class OddNumbersInAnArray { public static void main(String args[]){ int[] myArray = {23, 93, 56, 92, 39}; System.out.println("Even numbers in the given array are:: "); for (int i=0; i<myArray.length; i++){ if(myArray[i]%2 == 0){ System.out.println(myArray[i]); } } System.out.println("Odd numbers in the given array are:: "); for (int i=0; i<myArray.length; i++){ if(myArray[i]%2 != 0){ System.out.println(myArray[i]); } } } }
Output
Even numbers in the given array are:: 56 92 Odd numbers in the given array are:: 23 93 39
- Related Articles
- Java program to print odd and even number from a Java array.
- Print Even Positions Elements from an Array in Java
- Golang Program to Print the Largest Even and Largest Odd Number in a List
- How to find the Odd and Even numbers in an Array in java?
- Count number of even and odd elements in an array in C++
- Java program to find whether given number is even or odd
- Java Program to Check Whether a Number is Even or Odd
- Java Menu Driven Program to Check Positive Negative or Odd Even Number
- Every even number is followed by an odd number and every odd number is followed by an even number. What is the meaning ?
- C++ Program to Print “Even” or “Odd” without using conditional statement
- C Program to print “Even” or “Odd” without using Conditional statement
- Odd even sort in an array - JavaScript
- Java Program to Print even length words
- C++ Program to Check Whether Number is Even or Odd
- Python program to print the elements of an array present on odd position

Advertisements