Selection Sort Java Program

 import java.util.*;

public class cf 

{

static Scanner input = new Scanner(System.in);

public static void main(String[] args){

System.out.println("Enter the length of array");

int n=input.nextInt();

System.out.println("Now Enter the elements to sort");

int[] arr = new int[n];

for(int k=0;k<n;k++)

{

arr[k] = input.nextInt();

}

for(int i=0;i<n-1;i++){

for(int j=i+1;j<n;j++)

{

if(arr[j]<arr[i]){

int temp = arr[j];

arr[j] = arr[i];

arr[i] = temp;

}

}

}

for(int aa : arr)

System.out.print(aa+" ");

System.out.println("\n count="+count);

}

}


Popular Posts

Family Tree Project in Java

java:17: error: local variables referenced from a lambda expression must be final or effectively final count ++ ;

Creating basic tic tac toe android app using java