-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsortingArr.java
More file actions
37 lines (33 loc) · 1004 Bytes
/
sortingArr.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
import java.util.Arrays;
import java.util.Scanner;
public class sortingArr {
static int[] sorting(int[]arr){
int temp;
for (int i = 0; i < arr.length; i++) {
for (int j = i; j < arr.length; j++) {
if(arr[i] > arr[j]){
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
return arr;
}
public static void main(String[] args) {
int size;
System.out.println("enter size of array:");
Scanner inp = new Scanner(System.in);
size = inp.nextInt();
int[] arr = new int[size];
System.out.println("enter elements :");
for (int i = 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();
}
}