Java Math.ceil() metode
Det java.lang.Math.ceil () bruges til at finde den mindste heltalsværdi, der er større end eller lig med argumentet eller det matematiske heltal.
Syntaks
public static double ceil(double x)
Parameter
x= a value
Vend tilbage
This method returns smallest floating-point value that is greater than or equal to the argument and is equal to a mathematical integer.
- Hvis argumentet er positiv eller negativ dobbeltværdi, vil denne metode returnere loftværdi .
- Hvis argumentet er NaN , vil denne metode vende tilbage samme argument .
- Hvis argumentet er Uendelighed , vil denne metode vende tilbage Uendelighed med samme fortegn som argumentet.
- Hvis argumentet er positivt eller negativt Nul , vil denne metode vende tilbage Nul med samme fortegn som argumentet.
- Hvis argumentet er mindre end nul, men større end -1,0, vil denne metode returnere Negativ nul som produktion.
Eksempel 1
public class CeilExample1 { public static void main(String[] args) { double x = 83.56; // Input positive value, Output ceil value of x System.out.println(Math.ceil(x)); } } Test det nu Produktion:
84.0
Eksempel 2
public class CeilExample2 { public static void main(String[] args) { double x = -94.73; // Input negative value, Output ceil value of x System.out.println(Math.ceil(x)); } } Test det nu Produktion:
-94.0
Eksempel 3
public class CeilExample3 { public static void main(String[] args) { double x = -1.0 / 0; // Input negative infinity, Output negative infinity System.out.println(Math.ceil(x)); } } Test det nu Produktion:
-Infinity
Eksempel 4
public class CeilExample4 { public static void main(String[] args) { double x = 0.0; // Input positive zero, Output positive zero System.out.println(Math.ceil(x)); } } Test det nu Produktion:
0.0
Eksempel 5
public class CeilExample5 { public static void main(String[] args) { double x = -0.25; // Input less than zero but greater than -1.0, Output negative zero System.out.println(Math.ceil(x)); } } Test det nu Produktion:
-0.0