Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

Do certain Methods within the Math class only return a specific primitive type?

+7 votes
For example, Does Math.max only return integers, or does Math.pow only return doubles?
asked Oct 11, 2016 in CSC 211 (F16) by Hunter Bader (325 points)

2 Answers

+3 votes
 
Best answer

Math.pow() does only return doubles.

There are two versions (this is called "overloading") of Math.max(...):

Math.max(int, int) returns an int

Math.max(double,double) returns a double

Which method gets called depends on what parameter types you pass into it...

answered Oct 11, 2016 by Forrest Stonedahl (3,438 points)
selected Oct 11, 2016 by Hunter Bader
0 votes
For some of the methods within math, they return values based on the input. For example, if you do Math.max(int, int) in eclipse, it will return an int value, but if the inputs are double, the return value will be a double.
answered Oct 11, 2016 by Brandon Thompson (435 points)
...