-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab3.java
More file actions
40 lines (33 loc) · 1.03 KB
/
Lab3.java
File metadata and controls
40 lines (33 loc) · 1.03 KB
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
import java.util.Scanner;
class Lab3
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
System.out.println("Enter the size of the array: ");
int size = s.nextInt();
int[] array = new int[size];
System.out.println("Enter elements to insert into the array: ");
for(int i = 0; i < size; i++)
{
array[i] = s.nextInt();
}
System.out.print("Array Elements: ");
for(int i = 0; i < size; i++)
{
System.out.print(array[i] + " ");
}
int p, e;
System.out.println("\n Enter the position where you want to insert: ");
p = s.nextInt();
System.out.println("Enter the element which you want to insert: ");
e = s.nextInt();
array[p - 1] = e;
System.out.println("Array Elements: ");
for(int i = 0; i < size; i++)
{
System.out.print(array[i] + " ");
}
s.close();
}
}