import java.util.*;
public class Reverse {
public static void main(String[] args) {
int n,i,j=0,k=0;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int a[] = new int[n];
int even[]=new int[n];
int odd[]=new int[n];
for(i=0; i<n; i++)
{
a[i] = sc.nextInt();
}
for(i=0;i<n;i++)
{
if(a[i]%2==0)
{
even[j]=a[i];
j++;
}
else
{
odd[k]=a[i];
k++;
}
}
System.out.println("The even array is");
for(i=0; i<j; i++)
{
System.out.print(even[i]+ " ");
}
System.out.println("\nThe odd array is");
for(i=0; i<k; i++)
{
System.out.print(odd[i]+ " ");
}
}
}
public class Reverse {
public static void main(String[] args) {
int n,i,j=0,k=0;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int a[] = new int[n];
int even[]=new int[n];
int odd[]=new int[n];
for(i=0; i<n; i++)
{
a[i] = sc.nextInt();
}
for(i=0;i<n;i++)
{
if(a[i]%2==0)
{
even[j]=a[i];
j++;
}
else
{
odd[k]=a[i];
k++;
}
}
System.out.println("The even array is");
for(i=0; i<j; i++)
{
System.out.print(even[i]+ " ");
}
System.out.println("\nThe odd array is");
for(i=0; i<k; i++)
{
System.out.print(odd[i]+ " ");
}
}
}
i/p:
7
1 2 3 4 5 6 7
o/p:
The even array is
2 4 6
The odd array is
1 3 5 7
No comments:
Post a Comment