Once you click post assignment, learners in the selected class will immediately be able to see and complete this assignment
Back to Classroom
Floor
Java Basics Course
Engineers From These Top Companies and Universities Trust EXLskills
1M+ Professionals | 100+ Institutions
This is the EXLskills free and open-source Java Basics Course. It guides learners via explanation, demonstration, and thorough practice, from no more than a basic understanding of Java, to a moderate level of essential coding proficiency.
-->
Is this course FREE?
Yes, this a 100% free course that you can contribute to on GitHub here!
The floor function returns the largest whole number that is less than or equal to the input. This method only takes and returns double values. Take a look at the example below.
FloorMethodExample.java
package exlcode;
public class FloorMethodExample {
// Returns largest integer that is less than or equal to the argument
public static double exampleVariableOne = Math.floor(10.4);
public static double exampleVariableTwo = Math.floor(-20.4);
public static void main(String[] args) {
System.out.println(exampleVariableOne);
System.out.println(exampleVariableTwo);
}
}
As the nearest whole number that is less than or equal to 10.4 is 10, 10.0 is printed. Similarly, since the closest whole number that is less than or equal to -20.4 is -21, -21.0 is printed. Notice that even if we input a non-decimal number into the floor function, a double is returned. Since data precision is not hindered when you convert from an int data type to a double, Java will do it without throwing any errors. The floor function's primary use is rounding, all ready for you to use while coding.