-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortArray.java
More file actions
41 lines (30 loc) · 916 Bytes
/
SortArray.java
File metadata and controls
41 lines (30 loc) · 916 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
//6:Write a java program to sort array.
import java.util.Scanner;
import java.util.Arrays;
public class SortArray {
public static void main(String[] args) {
int size;
Scanner input = new Scanner(System.in);
System.out.print("Enter Array size :");
size=input.nextInt();
int arr[ ] = new int[ size ];
for(int index=0;index<arr.length;index++) {
System.out.print("Enter Array Elements :");
arr[ index ] = input.nextInt();
}
System.out.println();
System.out.println("Unsorted Array Elements are :"+Arrays.toString(arr));
for(int count=0;count<arr.length;count++) {
for(int index=0;index<arr.length-1;index++) {
if(arr[index]>arr[index+1]) {
int temp = arr[index];
arr[ index ] = arr[ index+1 ];
arr[ index+1 ] =temp;
}
}
}
System.out.println();
System.out.println("Sorted Array Elements are :"+Arrays.toString(arr));
input.close();
}
}