-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortingValues.java
More file actions
37 lines (31 loc) · 784 Bytes
/
Copy pathSortingValues.java
File metadata and controls
37 lines (31 loc) · 784 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
public class SortingValues
{
public static void main( String[] args )
{
int[] arr = { 45, 87, 39, 32, 93, 86, 12, 44, 75, 50 };
// Display the original (unsorted values)
System.out.print("before: ");
for ( int i=0; i<arr.length; i++ )
System.out.print( arr[i] + " " );
System.out.println();
int temp = 0;
// Swap the values around to put them ascending order.
for ( int i=0; i<arr.length-1; i++ )
{
for (int n=0; n<arr.length-2; n++ )
{
if ( arr[n] > arr[n+1])
{
temp = arr[n];
arr[n]=arr[n+1];
arr[n+1] = temp;
}
}
}
// Display the values again, now (hopefully) sorted.
System.out.print("after : ");
for ( int i=0; i<arr.length; i++ )
System.out.print( arr[i] + " " );
System.out.println();
}
}