- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsortingArr.java
More file actions
Latest commit
37 lines (33 loc) · 1004 Bytes
/
Copy pathsortingArr.java
File metadata and controls
37 lines (33 loc) · 1004 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
importjava.util.Arrays;
importjava.util.Scanner;
publicclasssortingArr {
staticint[] sorting(int[]arr){
inttemp;
for (inti = 0; i < arr.length; i++) {
for (intj = i; j < arr.length; j++) {
if(arr[i] > arr[j]){
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
returnarr;
}
publicstaticvoidmain(String[] args) {
intsize;
System.out.println("enter size of array:");
Scannerinp = newScanner(System.in);
size = inp.nextInt();
int[] arr = newint[size];
System.out.println("enter elements :");
for (inti = 0; i < arr.length; i++) {
System.out.print(i+1+". element: ");
arr[i] = inp.nextInt();
System.out.println();
}
sorting(arr);
System.out.println(Arrays.toString(arr));
inp.close();
}
}