Skip to content

Commit 783b225

Browse files
Update selection_sort.java
1 parent 9ee35e3 commit 783b225

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Sorting Algorithms/selection_sort.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/* In the following Java program, we ask user to enter the array elements or number,
2+
then we compare the array's element and start swapping with the variable temp.
3+
Put the first element in the temp and the second element in the first,
4+
and then temp in the second number and continue for the next match to sort the whole
5+
array in ascending order. */
6+
17
import java.util.Scanner;
28

39
public class SelectionSortExample2
@@ -8,13 +14,13 @@ public static void main(String args[])
814
int arr[] = new int[50];
915
Scanner scan = new Scanner(System.in);
1016

11-
System.out.print("Enter Array Size : ");
17+
System.out.print("Enter Array Size : "); // size of array taken from user.
1218
size = scan.nextInt();
1319

1420
System.out.print("Enter Array Elements : ");
1521
for(i=0; i<size; i++)
1622
{
17-
arr[i] = scan.nextInt();
23+
arr[i] = scan.nextInt(); // enter elements in array.
1824
}
1925

2026
System.out.print("Sorting Array using Selection Sort Technique..\n");
@@ -34,7 +40,7 @@ public static void main(String args[])
3440
System.out.print("Now the Array after Sorting is :\n");
3541
for(i=0; i<size; i++)
3642
{
37-
System.out.print(arr[i]+ " ");
43+
System.out.print(arr[i]+ " "); // printing the sorted array.
3844
}
3945
}
4046
}

0 commit comments

Comments
 (0)