Write a java program to add element in user-specified position using array

Write a java program to add element in user-specified position using array. In a given Array, a Java program to add an element in a specific position. Enter the array’s size, followed by all of the array’s elements. Now type in the element you want to insert and the location where you want it to go. We shift all the elements in the array by one to make it easier to insert the element.

 import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int n, pos, x;
Scanner s = new Scanner(System.in);
System.out.print("Enter no. of elements you want in array");
n = s.nextInt();
int a[] = new int[n+1];
System.out.println("Enter all the elements");
for(int i = 0; i < n; i++)
{
a[i] = s.nextInt();
}
System.out.print("Enter the position where you want to add the element");
pos = s.nextInt();
System.out.print("Enter the element you want to add");
x = s.nextInt();
for(int i = (n-1); i >= (pos-1); i--)
{
a[i+1] = a[i];
}
a[pos-1] = x;
System.out.print("After adding the element");
for(int i = 0; i < n; i++)
{
System.out.print(a[i]+",");
}
System.out.print(a[n]);
}
}

Enter no. of elements you want in array5
Enter all the elements
23
45
67
78
55
Enter the position where you want to add the element3
Enter the element you want to add100
After adding the element23,45,100,67,78,55