-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSort.java
35 lines (33 loc) · 870 Bytes
/
Sort.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
import java.util.*;
public class Sort
{
public static void sort(int[] array)
{
int n=array.length;
for(int i=0;i<n-1;++i){
for(int j=i+1;j<n;++j){
if(array[i]>array[j]){
array[i]=(array[i]+array[j])-(array[j]=array[i]);
}
}
}
}
public static void main(String[] args)
{
int n;
Scanner sc=new Scanner(System.in);
System.out.print("Enter Array Size:");
n=sc.nextInt();
int[] array = new int[n];
System.out.println("Enter Array elements: ");
for(int i=0; i<n; i++)
{
array[i]=sc.nextInt();
}
sort(array);
for (int i=0; i<n; i++)
{
System.out.print(array[i]+" ");
}
}
}