Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

sortare vector

public class HelloWorld{

     public static void main(String []args){
         int[] input = new int[] {3,4,31,0,-4};
         input = sortare(input);
         for (int i = 0; i < input.length; i++) {
             System.out.println("" + input[i]);
         }
        
     }
     static int[] sortare(int []a){
         for (int i = 0; i < a.length-1; i++) {
             int min = a[i];
                 int poz = i;
             for (int k = i+1; k < a.length; k++) {
                 
                 if (a[k] < min) {
                     min=a[k];
                     poz=k;
                 }
                
             }
             int aux = 0;
             aux = a[i];
             a[i]=a[poz];
             a[poz]=aux;
         }
         return a;
     }
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.