Simple way to learn | How to insert element (Specific position ) in Array.
- Here is the program for you how to insert element in specific position in array only integer value
- So we insert element in 10 in array and all the right side of array is shifted to +1 position and so on.(below image)
- Array means similar data types.
Program
public class InsertElement
{
public static void main(String[] args) {
int array[]={20,30,40,50,60}; //this element put in array
int position=4; //at position 4
int element=10; //10 put in 4 position
for (int i=array.length-1;i<position-1;i--)
{
array[i]=array[i-1];
}
array[position-1]=element;
for (int i=0;i<array.length;i++)
{
System.out.print(array[i]+" ");
}
}
}
Output :
Click to next or Start with your choice
- 4 ways to print Array in Java
- 2-D Array in Java
- Anonymous Array in Java
- Single Dimensional Array in Java
- Find Second Largest Number in Array
- Delete an Element in Array in Java
- Common Element in Array in Java
- Missing Element in Array
- Insert Element in Array
- Reverse Array in Java
- Merge Two Array in Java
- Smallest and Largest Elements in Array
- Find Odd and Even Number in Array
Sorting and Searching
Programs
Start with your
Choice
-Important Programs for Freshers
- Palindrome Number
- Prime
Number
- Swapping
Number
- Leap
Year
- Odd
and Even Number
- Fibonacci
Series
- Armstrong Number
- Factorial
Number
- Print
Table
Learn Pattern Programs
- Alphabet
pattern program in java
- Star Pattern Programs in Java
- Square
pattern programs in java
- Diamond
Star pattern programs in java
- Number
Pattern Programs in java
- Diagonal pattern program in java
Click
to Learn MySQL
for any complaint regarding my Blog please
visit contact us page and
write what problem you have!
Learn with us | HTML | CSS | Java Script |
Bootstrap | JAVA | ADV JAVA | MySQL
| GIT | Data Structure
No comments:
Post a Comment