Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #799 from webdesignerrps/patch-2
Create select.java
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import java.util.Scanner; | ||
|
||
public class SelectionSortExample2 | ||
{ | ||
public static void main(String args[]) | ||
{ | ||
int size, i, j, temp; | ||
int arr[] = new int[50]; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
Scanner scan = new Scanner(System.in); | ||
|
||
System.out.print("Enter Array Size : "); | ||
size = scan.nextInt(); | ||
|
||
System.out.print("Enter Array Elements : "); | ||
for(i=0; i<size; i++) | ||
{ | ||
|
||
|
||
|
||
|
||
arr[i] = scan.nextInt(); | ||
} | ||
|
||
System.out.print("Sorting Array using Selection Sort Technique..\n"); | ||
for(i=0; i<size; i++) | ||
{for(j=i+1; j<size; j++) | ||
{ if(arr[i] > arr[j]) | ||
{ | ||
temp = arr[i]; | ||
arr[i] = arr[j]; | ||
arr[j] = temp; | ||
} | ||
} | ||
} | ||
|
||
System.out.print("Now the Array after Sorting is :\n"); | ||
for(i=0; i<size; i++) | ||
{ | ||
System.out.print(arr[i]+ " "); | ||
} | ||
} | ||
} |