Skip to content

Instantly share code, notes, and snippets.

@jonathan-irvin
Last active August 29, 2015 14:19
Show Gist options
  • Save jonathan-irvin/75f621cb19b0f0273909 to your computer and use it in GitHub Desktop.
Save jonathan-irvin/75f621cb19b0f0273909 to your computer and use it in GitHub Desktop.
Sort integers
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