Skip to content

Instantly share code, notes, and snippets.

@thmain
Created February 23, 2016 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/eb9bd666660c7cdcd8ff to your computer and use it in GitHub Desktop.
Save thmain/eb9bd666660c7cdcd8ff to your computer and use it in GitHub Desktop.
public class Sorting3Integers {
// sort 3 given integers, sort them with out using if conditions
public void sort(int x, int y, int z){
int max,mid,min;
max = Math.max(x,Math.max(y, z));
min = -Math.max(-x,Math.max(-y, -z));
mid = (x+y+z)-(max+min);
System.out.println("Sorted order " + min + " " + mid + " " + max);
}
public static void main(String[] args) {
int x = 4;
int y = 1;
int z = 9;
Sorting3Integers s = new Sorting3Integers();
s.sort(x, y, z);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment