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
21 changes: 18 additions & 3 deletions src/assignments/sravanthi/Assignment2.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
package assignments.sravanthi;

import java.util.Arrays;

public class Assignment2 {

// Write a reusable program to sort an array in a reverse order
// ex: int[] arr = {3,5,2,1,4} -> o/p: {5,4,3,2,1}

public static void main(String[] args) {
// TODO Auto-generated method stub
public static void sortReverse(int[] arr) {
Arrays.sort(arr);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Develop the sorting logic.



System.out.print("Array in reverse order: {");
for (int i = arr.length - 1; i >= 0; i--) {
System.out.print(+arr[i]);
if(i !=0) {
System.out.print(",");
}
}System.out.println("}");
}

}
public static void main(String[] args) {
int[] numbers = {5, 2, 8, 1, 3,0};

sortReverse(numbers);
}
}