Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions src/Ascending.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,21 @@
public class Ascending {
public static void main(String[] args)
// comment added checked
//Sort an array into ascending order
{
int[] arr = { 10, 9, 8, 6, 3, 11, 11, 11, 1, 1, 9, 8, 7 };
int temp1 = 0;
for (int i = 0; i < arr.length - 1; i++) {
for (int j = 0; j < arr.length - i - 1; j++) {
if (arr[j] < arr[j + 1]) {
temp1 = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp1;

if (arr[j] > arr[j + 1]) {
arr[j] = arr[j] + arr[j+1];
arr[j+1] = arr[j] - arr[j+1];
arr[j] = arr[j] - arr[j+1];
}
}
}
/* sorted for descending order */
//Printing array elements
for (int i = 0; i < arr.length - 1; i++) {
if (arr[i] == arr[i + 1])
continue;
else {
System.out.print(arr[i + 1]);
break;
}
}
System.out.println(arr[i]);
}
}
} // this comment to check conflicts