Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
15 views

Selection Sort Java

selection program

Uploaded by

kv ns
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Selection Sort Java

selection program

Uploaded by

kv ns
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1. Write a java program to perform the selection sort?

2. import java.util.Scanner;
3.
4. public class SelectionSortExample2
5. {
6. public static void main(String args[])
7. {
8. int size, i, j, temp;
9. int arr[] = new int[50];
10. Scanner scan = new Scanner(System.in);
11.
12. System.out.print("Enter Array Size : ");
13. size = scan.nextInt();
14.
15. System.out.print("Enter Array Elements : ");
16. for(i=0; i<size; i++)
17. {
18. arr[i] = scan.nextInt();
19. }
20.
21. System.out.print("Sorting Array using Selection Sort Technique..\n");
22. for(i=0; i<size; i++)
23. {
24. for(j=i+1; j<size; j++)
25. {
26. if(arr[i] > arr[j])
27. {
28. temp = arr[i];
29. arr[i] = arr[j];
30. arr[j] = temp;
31. }
32. }
33. }
34.
35. System.out.print("Now the Array after Sorting is :\n");
36. for(i=0; i<size; i++)
37. {
38. System.out.print(arr[i]+ " ");
39. }
40. }
41. }

You might also like