-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsertAtEnd.java
More file actions
34 lines (25 loc) · 844 Bytes
/
InsertAtEnd.java
File metadata and controls
34 lines (25 loc) · 844 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
import java.util.Scanner;
class InsertAtEnd {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the size of the Array :");
int sizeOfArray=sc.nextInt();
System.out.println("Enter the Array :");
int arr[]=new int[sizeOfArray]; //input an array
for(int i=0;i<sizeOfArray-1;i++){
int x=sc.nextInt();
arr[i]=x;
}
System.out.println("Enter the insert Element :");
int element=sc.nextInt();
insert(arr,sizeOfArray,element);
System.out.println("Modified Array:");
for(int i=0;i<sizeOfArray;i++){
System.out.println(arr[i]+ " "); //printing the array
}
}
public static void insert(int ar[],int n,int x){
ar[n-1]=x;
return;
}
}