Skip to content

Instantly share code, notes, and snippets.

@mgronhol
Created September 23, 2012 11:43
Show Gist options
  • Save mgronhol/3769937 to your computer and use it in GitHub Desktop.
Save mgronhol/3769937 to your computer and use it in GitHub Desktop.
Sort three entries
public class Sorttaa {
public static int sorttaa( int a, int b, int c, int monesko ){
int tmp;
if ( a > b ){
tmp = b;
b = a;
a = tmp;
}
if( a > c ){
tmp = c;
c = a;
a = tmp;
}
if( b > c ){
tmp = c;
c = b;
b = tmp;
}
switch( monesko ){
case 1:
tmp = a;
break;
case 2:
tmp = b;
break;
case 3:
tmp = c;
break;
default: tmp = c;
}
return tmp;
}
public static void main( String[] args ){
System.out.println( sorttaa( 3, 2, 1, 1 ) );
System.out.println( sorttaa( 3, 2, 1, 2 ) );
System.out.println( sorttaa( 3, 2, 1, 3 ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment