The abs() method takes args as int, long, float or double. I passed it a value of type 'short' and it seemed to take it without a problem? Are there other value types that this can take...or was my value converted to an int? - Mike
Nain Hwu
Ranch Hand
Joined: Sep 16, 2001
Posts: 139
posted
0
Mike, Short arguments in a method invokation are converted to int. See JLS 5.3
Madhav Lakkapragada
Ranch Hand
Joined: Jun 03, 2000
Posts: 5040
posted
0
Are there other value types that this can take... umm....yes! char.
or was my value converted to an int? yup! Remember enlarging conversions are done automatically. However, you need a cast to do the shortening conversions. - satya
Because abs() accepts double type variable/constant as an argument, you can pass any variable which can be casted into double. In this case, except byte, you can pass any primitive type data as an argument to abs().
Originally posted by Mike Cunningham: The abs() method takes args as int, long, float or double. I passed it a value of type 'short' and it seemed to take it without a problem? Are there other value types that this can take...or was my value converted to an int? - Mike
------------------ Sreenivasa Kumar Majji Sun Certified Java Programmer SCJP Mock Test
Sreenivasa Majji
Jim Hall
Ranch Hand
Joined: Nov 29, 2001
Posts: 162
posted
0
Originally posted by sreenivasa majji: Because abs() accepts double type variable/constant as an argument, you can pass any variable which can be casted into double. In this case, except byte, you can pass any primitive type data as an argument to abs().
Except byte, what's wrong with byte? <code><pre> public class Test { public static void main(String[] args) { byte b = -32; System.out.println(Math.abs(b)); } } Output: 32 </pre></code>
[This message has been edited by Jim Hall (edited December 18, 2001).]