Skip to main content
Question Protected by rolfl
Tweeted twitter.com/#!/StackCodeReview/status/495236591162765313
added 29 characters in body; edited tags; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Find min of 3 numbers hardcoded, is it better than nested if statements?

 public static int min(int a, int b, int c) { int result = 0 ; if( a < b && a < c && b < c) result = a ; else if( a < b && a < c && b > c) result = a ; else if( a > b && a < c && b < c) result = b ; else if( a < b && b > c && c < a) result = c ; else if( a > b && b < c && a > c) result = b ; else if( a > b && a > c && c < b) result = c ; return result ;  } 

Is it better than nested if statements? Is there a more readable solution than this? To me it looks pretty readable, but I'm not sure whether it can be improved.

Find min of 3 numbers hardcoded, is it better than nested if statements?

 public static int min(int a, int b, int c) { int result = 0 ; if( a < b && a < c && b < c) result = a ; else if( a < b && a < c && b > c) result = a ; else if( a > b && a < c && b < c) result = b ; else if( a < b && b > c && c < a) result = c ; else if( a > b && b < c && a > c) result = b ; else if( a > b && a > c && c < b) result = c ; return result ;  } 

Is there a more readable solution than this? To me it looks pretty readable, but I'm not sure whether it can be improved.

Find min of 3 numbers hardcoded

public static int min(int a, int b, int c) { int result = 0 ; if( a < b && a < c && b < c) result = a ; else if( a < b && a < c && b > c) result = a ; else if( a > b && a < c && b < c) result = b ; else if( a < b && b > c && c < a) result = c ; else if( a > b && b < c && a > c) result = b ; else if( a > b && a > c && c < b) result = c ; return result ; } 

Is it better than nested if statements? Is there a more readable solution than this? To me it looks pretty readable, but I'm not sure whether it can be improved.

whoops, left in a grammar error in my last edit
Source Link
Pimgd
  • 22.6k
  • 5
  • 68
  • 144
 public static int min(int a, int b, int c) { int result = 0 ; if( a < b && a < c && b < c) result = a ; else if( a < b && a < c && b > c) result = a ; else if( a > b && a < c && b < c) result = b ; else if( a < b && b > c && c < a) result = c ; else if( a > b && b < c && a > c) result = b ; else if( a > b && a > c && c < b) result = c ; return result ; } 

Is there a more readable solution thatthan this? To me it looks pretty readable, but I'm not sure whether it can be improved.

 public static int min(int a, int b, int c) { int result = 0 ; if( a < b && a < c && b < c) result = a ; else if( a < b && a < c && b > c) result = a ; else if( a > b && a < c && b < c) result = b ; else if( a < b && b > c && c < a) result = c ; else if( a > b && b < c && a > c) result = b ; else if( a > b && a > c && c < b) result = c ; return result ; } 

Is there a more readable solution that this? To me it looks pretty readable, but I'm not sure whether it can be improved.

 public static int min(int a, int b, int c) { int result = 0 ; if( a < b && a < c && b < c) result = a ; else if( a < b && a < c && b > c) result = a ; else if( a > b && a < c && b < c) result = b ; else if( a < b && b > c && c < a) result = c ; else if( a > b && b < c && a > c) result = b ; else if( a > b && a > c && c < b) result = c ; return result ; } 

Is there a more readable solution than this? To me it looks pretty readable, but I'm not sure whether it can be improved.

removed tag from title, rephrased question
Source Link
Pimgd
  • 22.6k
  • 5
  • 68
  • 144
 public static int min(int a, int b, int c) { int result = 0 ; if( a < b && a < c && b < c) result = a ; else if( a < b && a < c && b > c) result = a ; else if( a > b && a < c && b < c) result = b ; else if( a < b && b > c && c < a) result = c ; else if( a > b && b < c && a > c) result = b ; else if( a > b && a > c && c < b) result = c ; return result ; } 

Is there a more readable solution that that this? To me it looks pretty readable

I m asking to review my code, but I'm not sure whether it can be improved.

 public static int min(int a, int b, int c) { int result = 0 ; if( a < b && a < c && b < c) result = a ; else if( a < b && a < c && b > c) result = a ; else if( a > b && a < c && b < c) result = b ; else if( a < b && b > c && c < a) result = c ; else if( a > b && b < c && a > c) result = b ; else if( a > b && a > c && c < b) result = c ; return result ; } 

Is there more readable solution that that? To me it looks pretty readable

I m asking to review my code

 public static int min(int a, int b, int c) { int result = 0 ; if( a < b && a < c && b < c) result = a ; else if( a < b && a < c && b > c) result = a ; else if( a > b && a < c && b < c) result = b ; else if( a < b && b > c && c < a) result = c ; else if( a > b && b < c && a > c) result = b ; else if( a > b && a > c && c < b) result = c ; return result ; } 

Is there a more readable solution that this? To me it looks pretty readable, but I'm not sure whether it can be improved.

Has nothing to do with functional programming
Link
Yuushi
  • 11.1k
  • 2
  • 31
  • 66
Loading
Source Link
ERJAN
  • 897
  • 4
  • 10
  • 14
Loading