Given below is the program that checks if all the elements in an integer array are odd.
class odd
{
public static void main(String args[])
{
int arr[]={11,21,13,79,11,17};
int flag=1;
for(int i=0;i<arr.length;i++)
{
//checking if array contains an even integer
if(arr[i]%2==0)
flag=0;
}
if(flag==0)
{
System.out.println("Array contains even integers.");
}
else
{
System.out.println("Array contains only odd integers.");
}
}
}
OUTPUT:
Array contains only odd integers.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Given below is the program that checks if all the elements in an integer array are odd.