Java – how to write a method that accepts int variables and returns the maximum value?
•
Java
I'm trying to write a method to compare three numbers and return the largest number
This is my code, but it doesn't work
public int max(int x,int y,int z){ return Math.max(x,y,z); }
How can my code be corrected?
Solution
Try this
public int max(int x,Math.max(y,z)); }
Math. The max () method only accepts 2 parameters, so if you want to compare 3 numbers according to the above code, you need to execute this method twice
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码