Last active
August 29, 2015 14:19
-
-
Save jonathan-irvin/75f621cb19b0f0273909 to your computer and use it in GitHub Desktop.
Sort integers
This file contains hidden or 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
import java.util.Scanner; | |
import java.util.Arrays; | |
public class IntSort { | |
public static void main(String[] args) { | |
Scanner input = new Scanner(System.in); | |
//How many numbers to sort | |
int totalnums = 3; | |
//init num array with above var | |
int num[] = new int[totalnums]; | |
//init counter | |
int i; | |
//Loop through all numbers we seek | |
for(i=0;i<totalnums;i++){ | |
System.out.print("Enter Number "+(i+1)+": "); | |
num[i] = input.nextInt(); | |
} | |
//Display a cool message | |
System.out.print("Sorting...\n"); | |
//Actually do work | |
Arrays.sort(num); | |
//Output the sorted list on a new line. | |
for (i=0;i<totalnums;i++){ | |
System.out.println(num[i]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment