math - Find the max of 3 numbers in Java with different data types -
say have following 3 constants:
final static int my_int1 = 25; final static int my_int2 = -10; final static double my_double1 = 15.5;
i want take 3 of them , use math.max()
find max of 3 if pass in more 2 values gives me error. instance:
// gives me error double maxofnums = math.max(my_int1, my_int2, my_double2);
please let me know i'm doing wrong.
math.max
takes 2 arguments. if want maximum of three, use math.max(my_int1, math.max(my_int2, my_double2))
.
Comments
Post a Comment