import java.util.*;
public class Splitting
{
public static void main(String[] args)
{
int n, x, flag=0,pos=0,k=0,j=0,i;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int a[] = new int[n];
int b[] = new int[n];
int c[] = new int[n];
for (i = 0; i < n; i++)
{
a[i] = sc.nextInt();
}
pos = sc.nextInt();
for(i=0;i<pos;i++)
{
b[k] = a[i];
k++;
}
for(i=pos;i<n;i++)
{
c[j] = a[i];
j++;
}
System.out.print("First array:");
for(i = 0;i<k;i++)
{
System.out.print(b[i]+" ");
}
System.out.println(" ");
System.out.print("Second array:");
for(i=0;i<j;i++)
{
System.out.print(c[i]+" ");
}
}
}
i/p: 5
1 2 3 4 5
2
o/p:
First array:1 2
Second array:3 4 5
public class Splitting
{
public static void main(String[] args)
{
int n, x, flag=0,pos=0,k=0,j=0,i;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int a[] = new int[n];
int b[] = new int[n];
int c[] = new int[n];
for (i = 0; i < n; i++)
{
a[i] = sc.nextInt();
}
pos = sc.nextInt();
for(i=0;i<pos;i++)
{
b[k] = a[i];
k++;
}
for(i=pos;i<n;i++)
{
c[j] = a[i];
j++;
}
System.out.print("First array:");
for(i = 0;i<k;i++)
{
System.out.print(b[i]+" ");
}
System.out.println(" ");
System.out.print("Second array:");
for(i=0;i<j;i++)
{
System.out.print(c[i]+" ");
}
}
}
i/p: 5
1 2 3 4 5
2
o/p:
First array:1 2
Second array:3 4 5
No comments:
Post a Comment