Created
February 23, 2016 23:42
-
-
Save thmain/eb9bd666660c7cdcd8ff to your computer and use it in GitHub Desktop.
This file contains 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
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