public class Sort50 {
public static void main(String[] args) {
int[] arr = { 12, 43, 55, 42, 76, 98, 67, 50 };
for (int j = 0; j < arr.length - 1; j++) {
for (int i = 0; i < arr.length - 1 - j; i++) {
if (Math.abs(arr[i] - 50) > Math.abs(arr[i + 1] - 50)) {
int temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
}
}
}
for (int x = 0; x < arr.length; x++) {
System.out.print(arr[x]+" ");
}
}
}
|