Java Source Code: Sort Numbers in Selection Sort

Java Source Code: Sort Numbers in Selection Sort
New HTC Windows Phone 8S A620e Black White Unlocked for Any GSM Carrier
Current Bid: $209.99

Below is the sample java source code on sorting numbers using selection sort. Selection Sort in java is much prepared by the programmers when it comes on sorting. Here, I will present to you on how the selection sort works.

How Selection Sort works in Java?

Assuming the user entered 6 numbers which are:

4 5 1 3 2 6

The program will sort it in an ascending order using selection sort. The program will simply compare the first number which is 4 to the second number, third number and so on, and then sort. See below on how it works.

From the entered numbers 4 5 1 3 2 6

Sorted To:

5 1 3 2 4 6

1 3 2 4 5 6

1 2 3 4 5 6 //sorting ends here and this will be output to the screen.

Sorting in selection sort is pretty fast than bubble sort. But If you are interested on comparing other methods of sorting like bubble sort , you can visit the link below.

source:linux-mag.com
Java Source Code: How to Sort Numbers in Bubble Sort Using Recursion

Below is the java source code for Selection Sort.

Java Source Code: How to Sort Numbers using Selection Sort

//java class
public class SelectionSort
{
public void SelectionSort(int[] arr){
for(int i=0; iJava Tutorials and Tips

Java Tutorial Examples
5 Important Tips to Learn Java Programming and Other Programming Languages
Basic Knowledge Required in Programming
How to Program in Java: Complete Simple Easy Steps
Java Simple Codes for Beginners
Java Tutorial for Beginners: A Beginners Guide on Learning Java Programming
Java Class: Learn More About Classes in Java

Sample Output:

Enter the size of the array: 10

Enter 10 numbers: 500 600 250 1000 35 50 10 15 20 1

The Sorted numbers: 1 10 15 20 35 50 250 500 600 1000

Java Video Tutorials

Java Programming Video Training tutorials CBT 30+ Hrs
Current Bid: $4.99
Advanced Java Programming Video Training tutorials CBT – 30+ Hrs – Master level
Current Bid: $4.99
Learn JAVA language -14h video & docs tutorials
Current Bid: $4.59

Java Books

Java Jumpstart : A Beginner’s Guide to Internet Programming by Noel Enete…
Current Bid: $14.95
Java Programming for the Absolute Beginner by John P. Flynt (2006, Paperback,…
Current Bid: $79.95

Other Java Source Code Examples

Java Source Code: Sort Numbers in Bubble Sort
Java Simple Codes for Beginners
A Java source code: How to Output Asterisk in Different Forms Using Recursion
Java Source Code: A Recursive Asterisk Diamond Shape
Java Source code on Printing the Greatest Common Divisor (GCD) using Recursion
Java Source code: How to Print a String Backward using Recursion
Java Source code: How to Add Numbers inside an Array using For Loop
Java Source code: How to Add numbers inside an Array Using Recursion
Java Source Code on a Recursive Linear Search
Java Source Code: Binary Search in Recursion
Java source code: How to Output the Answer of the Integer X to the Power Y
Java Source Code: How to make a Program that will determine a Person’s Salutation and Current Age
Java Source Code: Recursive Snow Flakes