Find the max of 3 numbers in Java with different data types

前端 未结 12 1905
情深已故
情深已故 2020-12-03 00:33

Say I have the following three constants:

final static int MY_INT1 = 25;
final static int MY_INT2 = -10;
final static double MY_DOUBLE1 = 15.5;
12条回答
  •  遥遥无期
    2020-12-03 01:29

    int first = 3;  
    int mid = 4; 
    int last = 6;
    
    //checks for the largest number using the Math.max(a,b) method
    //for the second argument (b) you just use the same method to check which  //value is greater between the second and the third
    int largest = Math.max(first, Math.max(last, mid));
    

提交回复
热议问题