math 计算float
数学类静态浮点数min(float f1,float f2) (Math Class static float min(float f1 , float f2) )
This method is available in java.lang package.
此方法在java.lang包中可用。
This method is used to return the minimum one of both the given arguments or in other words this method returns the smallest value of the given two arguments.
此方法用于返回给定两个参数中的最小值。换句话说,此方法返回给定两个参数中的最小值。
This is a static method so this method is accessible with the class name too.
这是一个静态方法,因此也可以使用类名访问此方法。
The return type of this method is float, it returns the smallest element from the given two arguments.
此方法的返回类型为float ,它从给定的两个参数返回最小的元素。
This method accepts two arguments of float values.
此方法接受浮点值的两个参数。
This method does not throw any exception.
此方法不会引发任何异常。
Syntax:
句法:
public static float min(float f1, float f2){
}
Parameter(s): float f1, float f2 – two float values, in which we have to find the smallest/minimum value.
参数: float f1,float f2 –两个浮点值,我们必须在其中找到最小/最小值。
Return value:
返回值:
The return type of this method is float, it returns the smallest/minimum value.
此方法的返回类型为float ,它返回最小值/最小值。
Note:
注意:
If we pass "NaN" (Not a Number), it returns the same value i.e. "NaN".
如果我们传递“ NaN”(不是数字),它将返回相同的值,即“ NaN”。
If we pass zero (-0 or 0), it returns the 0.
如果传递零(-0或0),则返回0。
If we pass the same values in both parameters, it returns the same value.
如果我们在两个参数中传递相同的值,则它将返回相同的值。
Java程序演示min(float f1,float f2)方法的示例 (Java program to demonstrate example of min(float f1, float f2) method)
// Java program to demonstrate the example of
// min(float f1, float f2) method of Math Class.
public class MinFloatTypeMethod {
public static void main(String[] args) {
// declaring variables
float f1 = -0.0f;
float f2 = 0.0f;
float f3 = -0.6f;
float f4 = 124.58f;
// displaying the values
System.out.println("f1: " + f1);
System.out.println("f2: " + f2);
System.out.println("f3: " + f3);
System.out.println("f4: " + f4);
// Here , we will get (-0.0) because we are passing parameter
// whose value is (-0.0f,0.0f)
System.out.println("Math.min(f1,f2): " + Math.min(f1, f2));
// Here , we will get (0.0) and we are passing parameter
// whose value is (0.0f,124.58f)
System.out.println("Math.min(f2,f4): " + Math.min(f2, f4));
}
}
Output
输出量
E:\Programs>javac MinFloatTypeMethod.java
E:\Programs>java MinFloatTypeMethod
f1: -0.0
f2: 0.0
f3: -0.6
f4: 124.58
Math.min(f1,f2): -0.0
Math.min(f2,f4): 0.0
翻译自: https://www.includehelp.com/java/math-class-static-float-min-float-f1-float-f2-with-example.aspx
math 计算float