A Brilliant Program: Insert an element into an array
For String programs clickhttps://wordpress-343193-1101484.cloudwaysapps.com/count-no-of-palindrome-words-in-a-sentence
Write a program to insert an element into an array. Ask the user to enter the number to enter and the position(index) where you want to insert the element.
For String programs click
Count palindrome words in a sentence: Best program
INSERT AN ELEMENT INTO AN ARRAY:
import java.io.*;
class insert
{
public static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the number of elements in the array");
int n=Integer.parseInt(br.readLine());
int len=n+1;
int Arr[]=new int[len];
System.out.println("Enter the values");
for(int i=0;i<n;i++)
Arr[i]=Integer.parseInt(br.readLine());
System.out.println("Enter the element to be inserted");
int num=Integer.parseInt(br.readLine());
System.out.println("Enter the index of the position of insertion of new element");
int index=Integer.parseInt(br.readLine());
for(int i=n-1;i>=index;i--)
{
Arr[i+1]=Arr[i];
}
Arr[index]=num;
n++;
System.out.println("THE ARRAY AFTER INSERTION");
for(int i=0;i<n;i++)
System.out.print(Arr[i]+"\t");
}
}Output:
Enter the number of elements in the array
4
Enter the values
21
33
78
44
Enter the element to be inserted
100
Enter the index of the position of insertion of a new element
2
THE ARRAY AFTER INSERTION
21
33
100
78
44
For other java videos
https://www.youtube.com/user/trushnatej
Related Posts
Continue learning with these related articles

String Methods in Java for ICSE Class 10: 25 Output Questions with Answers
ICSE Class 10 Computer Applications practice on String class methods: length, charAt, indexOf, lastIndexOf, substring, replace, trim, compareTo, equals and more, with 25 board-style output questions and step-by-step answers.

Special Number Programs in Java for ICSE: Armstrong, Spy, Neon, Disarium, Pronic and More
Every special number asked in ICSE Computer Applications – prime, perfect, Armstrong, palindrome, automorphic, neon, spy, Niven, duck, buzz, Disarium, special and pronic numbers – with definitions, examples and one complete Java program that checks them all.

Math Library Methods in Java for ICSE Class 9 (with Outputs)
ICSE Class 9 Computer Applications notes on the Java Math class: sqrt, cbrt, pow, abs, max, min, ceil, floor, round, rint and random, with return types, tricky negative-number outputs and Java expressions for formulas.