-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathone_dimensional_function.java
More file actions
135 lines (131 loc) · 4.15 KB
/
Copy pathone_dimensional_function.java
File metadata and controls
135 lines (131 loc) · 4.15 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package array;
import java.util.Scanner;
public final class one_dimensional_function {
int i;
Scanner objin = new Scanner(System.in);
void Input(int a[],int n)
{
for(i=0;i<n;i++)
{
System.out.print("Input Array :");
a[i] = objin.nextInt();
}
}
void Ouput(int a[],int n)
{
for(i=0;i<n;i++)
{
System.out.print(a[i]+" ");
}
}
int search(int a[],int n)
{
int svalue;
int index=-1;
System.out.println("Input Value to Search :");
svalue=objin.nextInt();
for(i=0;i<n;i++)
{
if(a[i]==svalue)
{
index=i;
break;
}
}
return index;
}
void Update(int a[],int n)
{
int nvalue;
int index=search(a, n);
if(index==-1)
{
System.out.println("........Search not Found.........");
}
else
{
System.out.print("Input New value :");
nvalue=objin.nextInt();
a[index]=nvalue;
System.out.println("Update Completed ..!");
}
}
void Delete(int a[],int n)
{
int index=search(a, n);
if(index==-1)
{
System.out.println(".......Search not Found.........");
}
else
{
for(i=index;i<n;i++)
{
a[i]=a[i+1];
}
n=n-1;
Ouput(a, n);
}
}
void Sort(int a[],int n)
{
int t,j;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
public one_dimensional_function()
{
int a[] = new int[100];
String st;
int n=0,op;
do{
System.out.println("1. Input ");
System.out.println("2. Output ");
System.out.println("3. Search ");
System.out.println("4. Update ");
System.out.println("5. Delete ");
System.out.println("6. Sort ");
System.out.print("Please Choose One Option :");
op=objin.nextInt();
switch (op) {
case 1 -> {
System.out.print("Input N :");
n=objin.nextInt();
Input(a, n);
}
case 2 -> {
Ouput(a, n);
}
case 3 -> {
int index=search(a,n);
if(index==-1)
System.out.println("Search not Found");
else
System.out.println("Seach Found At "+index);
}
case 4 -> {
Update(a, n);
}
case 5 -> {
Delete(a, n);
}
case 6 -> {
Sort(a, n);
}
}
System.out.println("\nPrees yes to Continue ...!");
System.out.println("Prees No to Stop ...!");
st=objin.next();
}while(st.equals("yes"));
}
public static void main(String[] args) {
new one_dimensional_function();
}
}