-
Notifications
You must be signed in to change notification settings - Fork 25
/
evenandodd.java
50 lines (50 loc) · 871 Bytes
/
evenandodd.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package Basics;
// Write a program to find if numbers entered are Odd or Even.
import java.util.*;
class evenandodd
{
public static void main(String args[])
{
int n,i;
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of elements: ");
n = sc.nextInt();
int a[] = new int [n];
int b[] = new int [n];
int c[] = new int [n];
System.out.println("Enter the elements: ");
for(i=0;i<n;i++)
{
a[i] = sc.nextInt();
}
for(i=0;i<n;i++)
{
if(a[i]%2==0)
{
b[i] = a[i];
}
else if(a[i]%2!=0)
{
c[i] = a[i];
}
}
System.out.print("Even Numbers Are: ");
for(i=0;i<n;i++)
{
if(b[i]!=0)
{
System.out.print(b[i] + " ");
}
}
System.out.println();
System.out.print("Odd Numbers Are: ");
for(i=0;i<n;i++)
{
if(c[i]!=0)
{
System.out.print(c[i] + " ");
}
}
sc.close();
}
}