-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathInsert.java
More file actions
27 lines (26 loc) · 751 Bytes
/
Insert.java
File metadata and controls
27 lines (26 loc) · 751 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
import java.util.Scanner;
class Insert
{
public static void main(String[] args)
{
int len, p,ele;
Scanner sc = new Scanner(System.in);
System.out.print("Enter length of an array:");
len = sc.nextInt();
int arr[] = new int[len+1];
System.out.println("Enter "+len+" elements:");
for(int i = 0; i < len; i++)
{
arr[i] = sc.nextInt();
}
System.out.print("Enter the element which you want to insert:");
ele = sc.nextInt();
arr[len] = ele;
System.out.print("After inserting : ");
for(int i = 0; i <len; i++)
{
System.out.print(arr[i]+",");
}
System.out.print(arr[len]);
}
}