Write a method called largerAbsVal that takes two integers as parameters and returns the larger of the two absolute values. A call of largerAbsVal(11, 2) would return 11, and a call of largerAbsVal(4, –5) would return 5.
Program:
public class Ch03Ex06
{
public static void main(String[] args)
{
int res1 = largerAbsVal(11, 2);
int res2 = largerAbsVal(4, -5);
System.out.println("largerAbsVal(11, 2): " + res1);
System.out.println("largerAbsVal(4, -5): " + res2);
}
public static int largerAbsVal(int n1, int n2)
{
return Math.max(Math.abs(n1), Math.abs(n2));
}
}
Output:
largerAbsVal(11, 2): 11
largerAbsVal(4, -5): 5