File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change
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
+
1
7
import java .util .Scanner ;
2
8
3
9
public class SelectionSortExample2
@@ -8,13 +14,13 @@ public static void main(String args[])
8
14
int arr [] = new int [50 ];
9
15
Scanner scan = new Scanner (System .in );
10
16
11
- System .out .print ("Enter Array Size : " );
17
+ System .out .print ("Enter Array Size : " ); // size of array taken from user.
12
18
size = scan .nextInt ();
13
19
14
20
System .out .print ("Enter Array Elements : " );
15
21
for (i =0 ; i <size ; i ++)
16
22
{
17
- arr [i ] = scan .nextInt ();
23
+ arr [i ] = scan .nextInt (); // enter elements in array.
18
24
}
19
25
20
26
System .out .print ("Sorting Array using Selection Sort Technique..\n " );
@@ -34,7 +40,7 @@ public static void main(String args[])
34
40
System .out .print ("Now the Array after Sorting is :\n " );
35
41
for (i =0 ; i <size ; i ++)
36
42
{
37
- System .out .print (arr [i ]+ " " );
43
+ System .out .print (arr [i ]+ " " ); // printing the sorted array.
38
44
}
39
45
}
40
46
}
You can’t perform that action at this time.
0 commit comments