Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SortArray {
- public static void main(String args[]) {
- int arr[] = {3,5,7,1,2};
- sortArray(arr);
- printArray(arr);
- }
- public static void sortArray(int arr[]){
- for(int i=0; i<arr.length; i++) {
- // find max
- int maxIndex = i;
- for(int k=i; k<arr.length; k++) {
- if( arr[k]>arr[maxIndex] ) {
- maxIndex = k;
- }
- }
- int temp = arr[i];
- arr[i] = arr[maxIndex];
- arr[maxIndex] = temp;
- }
- }
- public static void printArray(int arr[]) {
- for(int i=0; i<arr.length; i++) {
- System.out.print(arr[i] + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement