Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class trial {
- public static void main(String args[])
- {
- Scanner src=new Scanner(System.in);
- System.out.println("Enter the size of array");
- int a= src.nextInt();
- int arr[]=new int[a];
- System.out.println("Enter the numbers");
- for(int i=0;i<a;i++)
- {
- arr[i]=src.nextInt();
- }
- System.out.println("Enter the position at which you wish to split (position starts with 1)");
- int pos=src.nextInt();
- int pos3=pos;
- //int pos2=pos-1;
- int m=0,n=0;
- //System.out.println("The first part is");
- for(int j=0;j<pos;j++)
- {
- //System.out.println(arr[j]);
- m++;
- }
- //System.out.println("The second part is");
- for(int k=pos;k<a;k++)
- {
- //System.out.println(arr[k]);
- n++;
- }
- int arr2[]=new int[m];
- int arr3[]=new int[n];
- for(int p=0;p<m;p++)
- {
- arr2[p]=arr[p];
- }
- for(int q=0;q<n;q++)
- {
- arr3[q]=arr[pos3];
- pos3++;
- }
- System.out.println("The First new array is");
- for(int s=0;s<m;s++)
- {
- System.out.println(arr2[s]);
- }
- System.out.println("The second new array is");
- for(int t=0;t<n;t++)
- {
- System.out.println(arr3[t]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement