-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_oper.java
More file actions
55 lines (47 loc) · 1.5 KB
/
array_oper.java
File metadata and controls
55 lines (47 loc) · 1.5 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import java.util.Scanner;
public class array_oper{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
int[] arr=new int[100];
System.out.print("enter total size of arr: ");
int num=sc.nextInt();
if(num>100||num<0){
System.out.print("invalid ");
return;
}for(int i=0;i<num;i++){
arr[i]=sc.nextInt();
}
int choice=0;
while(choice<4){
System.out.println("\n=== MENU ===");
System.out.println("1. Insert element");
System.out.println("2. Delete element");
System.out.println("3. Display array");
System.out.println("4. Exit");
System.out.print("Enter your choice: ");
choice = sc.nextInt();
switch(choice){
case 1:
System.out.print("enter pos you want to enter: ");
int pos=sc.nextInt();
if(pos>num||pos<0){
System.out.print("invalid ");
break;
}
System.out.print("enter element you want to enter: ");
int elem=sc.nextInt();
for(int i=num;i>=pos;i--){
arr[i+1]=arr[i];
}arr[pos]=elem;
num++;
break;
default:
System.out.print("invalid choice");
case 3:
for(int i=0;i<num;i++){
System.out.print(arr[i]);
}
}
}
}
}