-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsertA.java
More file actions
59 lines (36 loc) · 869 Bytes
/
InsertA.java
File metadata and controls
59 lines (36 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// insert a element in array
import java.util.*;
public class InsertA
{
public static void main(String[] args)
{
int i,p,e,n;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the length of the array!= ");
n=sc.nextInt();
int a[]=new int[n];
System.out.println("Enter the Array Elemnt");
for(i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
int temp=0;
int len=a.length;
System.out.println("Enter the Position Where want to insert Element= ");
p=sc.nextInt();
System.out.println("Enter the Element = " );
e=sc.nextInt();
System.out.println();
System.out.println("Deleted Element= "+a[len-1]);
for(i=len-1;i>p-1;i--)
{
a[i]=a[i-1];
}
a[p-1]=e;
System.out.print("After INsertion Array = ");
for(i=0;i<n;i++)
{
System.out.print(" "+a[i]);
}
}
}