java - Return Min/Abs of 3 numbers -
i'm working on assignment i'm supposed return smallest of 3 values (absolute values, program states). worked when there 2 values needed returned, added 3rd one, started saying "cannot find symbol" @ math.min inside method. :( can't see problem is?
public class threeseven_rasmusds { //start of smallerabsval public static int smallerabsval(int a, int b, int c) { int val = (math.min(math.abs(a), math.abs(b), math.abs(c))); return val; } //end of smallerabsval public static void main(string[] args) { int val = smallerabsval(6, -9, -3); system.out.println(val); } //end of main } //end of class
the math.min
lib method accepts 2 parameters. if want min
of 3 values, need this:
math.min( a, math.min(b, c) );
in context:
int val = math.min(math.abs(a), math.min(math.abs(b), math.abs(c)));
Comments
Post a Comment