Middle of three using minimum comparisons | Java program to find middle of three distinct numbers ; Function to find the middle of three number ; Compare each three number to find middle number . Enter only if a > b ; Decided a is not greater than b . ; driver code
import java . util . * ; class Middle { public static int middleOfThree ( int a , int b , int c ) { if ( a > b ) { if ( b > c ) return b ; else if ( a > c ) return c ; else return a ; } else { if ( a > c ) return a ; else if ( b > c ) return c ; else return b ; } } public static void main ( String [ ] args ) { int a = 20 , b = 30 , c = 40 ; System . out . println ( middleOfThree ( a , b , c ) ) ; } }