-
Notifications
You must be signed in to change notification settings - Fork 0
/
QB 625.java
44 lines (37 loc) · 1001 Bytes
/
QB 625.java
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
//QB 625
import java.util.*;
class Run {
public static void main(String args[]) {
Array ab = new Array();
Scanner sc = new Scanner(System.in);
System.out.println("Enter for How many Elements:");
int n = sc.nextInt();
System.out.println("Enter Elements:");
int a[] = new int[n];
for (int i = 0; i < a.length; i++) {
a[i] = sc.nextInt();
}
ab.sort(a);
System.out.println("After sorting Elements:");
ab.display(a);
}
}
class Array {
void sort(int a[]) {
int temp;
for (int i = 0; i < a.length; i++) {
for (int j = i + 1; j < a.length; j++) {
if (a[i] > a[j]) {
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
}
void display(int a[]) {
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
}
}