Skip to content

Instantly share code, notes, and snippets.

@JRGGRoberto
Created December 1, 2014 22:56
Show Gist options
  • Save JRGGRoberto/00c837732d7a0ead5492 to your computer and use it in GitHub Desktop.
Save JRGGRoberto/00c837732d7a0ead5492 to your computer and use it in GitHub Desktop.
Ordena 3 números
import java.util.Scanner;
public class ordena {
public static void main(String[] args) {
int[] num = new int[3];
Scanner key = new Scanner(System.in);
System.out.print("N1:");
num[0] = key.nextInt();
System.out.print("N2:");
num[1] = key.nextInt();
System.out.print("N3:");
num[2] = key.nextInt();
key.close();
int aux;
if (num[0] > num[1]){
aux = num[0];
num[0] = num[1];
num[1] = aux;
}
if (num[1] > num[2]){
aux = num[1];
num[1] = num[2];
num[2] = aux;
}
if (num[0] > num[1]){
aux = num[0];
num[0] = num[1];
num[1] = aux;
}
System.out.println(num[0] +", "+ num[1] +", "+ num[2]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment