Advertisement
Nick-O-Rama

sortArray

Jan 28th, 2015
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. import java.util.Arrays;
  2.  
  3.  
  4. public class Sort_Search {
  5.  
  6.     public static void main(String[] args) {
  7.        
  8.         int[] myArray = {15,10,17,1,5,20,25};
  9.         printArray(myArray);
  10.         System.out.println();
  11.         sortArray(myArray);
  12.         printArray(myArray);
  13.     }
  14.    
  15.     public static void printArray(int[] arr)
  16.     {
  17.         for(int value: arr)
  18.         {
  19.             System.out.print(value + " ");
  20.         }
  21.     }
  22.    
  23.     public static void sortArray(int[] arr)
  24.     {
  25.         for (int i = 0; i < arr.length;i++)
  26.         {
  27.             int low = i;
  28.             for (int j = i+1; j < arr.length; j++)
  29.             {
  30.                 if (arr[j] < arr[low])
  31.                 {
  32.                     low = j;
  33.                 }
  34.  
  35.             }
  36.             int temp = arr[low];
  37.             arr[low] = arr[i];
  38.             arr[i] = temp;         
  39.         }
  40.     }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement