-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.java
More file actions
42 lines (32 loc) · 986 Bytes
/
Copy pathinterface.java
File metadata and controls
42 lines (32 loc) · 986 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
35
36
37
38
39
40
41
42
package shamitha;
import java.util.Arrays;
import java.util.Scanner;
interface Operation {
void perform();
}
class SortingOperation implements Operation {
private int[] arr;
public SortingOperation(int[] arr) {
this.arr = arr;
}
@Override
public void perform() {
Arrays.sort(arr);
System.out.println("Sorted Array: " + Arrays.toString(arr));
}
}
public class InterfaceExample {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the number of elements in the array: ");
int n = scanner.nextInt();
int[] arr = new int[n];
System.out.println("Enter the elements of the array: ");
for (int i = 0; i < n; i++) {
arr[i] = scanner.nextInt();
}
Operation operation = new SortingOperation(arr);
operation.perform();
scanner.close();
}
}