File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .util .Scanner ;
2
+
3
+ public class SelectionSortExample2
4
+ {
5
+ public static void main (String args [])
6
+ {
7
+ int size , i , j , temp ;
8
+ int arr [] = new int [50 ];
9
+ Scanner scan = new Scanner (System .in );
10
+
11
+ System .out .print ("Enter Array Size : " );
12
+ size = scan .nextInt ();
13
+
14
+ System .out .print ("Enter Array Elements : " );
15
+ for (i =0 ; i <size ; i ++)
16
+ {
17
+ arr [i ] = scan .nextInt ();
18
+ }
19
+
20
+ System .out .print ("Sorting Array using Selection Sort Technique..\n " );
21
+ for (i =0 ; i <size ; i ++)
22
+ {
23
+ for (j =i +1 ; j <size ; j ++)
24
+ {
25
+ if (arr [i ] > arr [j ])
26
+ {
27
+ temp = arr [i ];
28
+ arr [i ] = arr [j ];
29
+ arr [j ] = temp ;
30
+ }
31
+ }
32
+ }
33
+
34
+ System .out .print ("Now the Array after Sorting is :\n " );
35
+ for (i =0 ; i <size ; i ++)
36
+ {
37
+ System .out .print (arr [i ]+ " " );
38
+ }
39
+ }
40
+ }
You can’t perform that action at this time.
0 commit comments