-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArraySort.java
More file actions
34 lines (31 loc) · 983 Bytes
/
ArraySort.java
File metadata and controls
34 lines (31 loc) · 983 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
import java.util.*;
public class ArraySort {
public static void main(String[] args) {
int i;
Scanner a=new Scanner(System.in);
int array[]=new int[100];
System.out.print("Enter a size of array :- ");
int n=a.nextInt();
System.out.println("Enter a Array :- ");
for(i=0;i<n;i++){
array[i]=a.nextInt();
}
System.out.print("Display a array before sorting:- ");
for(i=0;i<n;i++){
System.out.print(array[i]+ " ");
}
for(i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(array[i]>array[j]){
int temp=array[i];
array[i]=array[j];
array[j]=temp;
}
}
}
System.out.print("\nDisplay a array after sorting:- ");
for(i=0;i<n;i++){
System.out.print(array[i]+ " ");
}
}
}