import java.util.*;
public class array {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int []ar=new int[20];
int i,j,n;
System.out.println("How many element u want ? ");
n=sc.nextInt();
System.out.println("Enter elements : ");
for(i=0;i<n;i++){
ar[i]=sc.nextInt();
}
System.out.print("Elements are : \n");
for(i=0;i<n;i++){
System.out.print(ar[i]+" ");
}
int val,pos;
System.out.println("\nEnter element to insert : ");
val=sc.nextInt();
System.out.println("Enter position to insert : ");
pos=sc.nextInt();
if(pos>=0 && pos<=n+1){
for(i=n;i>pos-1;i--){
ar[i]=ar[i-1];
}
ar[i]=val;
n++;
System.out.println("Updated arrray is : ");
for(i=0;i<n;i++){
System.out.print(ar[i]+" ");
}
}
else
System.out.println("Invalid position");
}
}
Output