Description: The java.io package provides classes for input and output operations. The Math class provides mathematical operations and functions. The floor function rounds a floating-point number down to the nearest integer.
Examples:
1. Using java.io package to read input from the user and applying Math.floor function to round down the input to the nearest integer:
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try { System.out.print("Enter a floating-point number: "); double number = Double.parseDouble(reader.readLine());
double floorNumber = Math.floor(number); System.out.println("The floor of " + number + " is " + floorNumber); } catch (IOException e) { e.printStackTrace(); } } }
Output: Enter a floating-point number: 8.6 The floor of 8.6 is 8.0
2. Using Math.floor to get the integer part of a number:
double number = 3.14159; int integerPart = (int) Math.floor(number); System.out.println(integerPart);
Output: 3
Package Library: The Math class is part of the java.lang package, which is automatically imported in every Java program. The java.io package is part of the Java SE platform, which provides a number of core classes and packages for handling input and output operations.
Java Math.floor - 30 examples found. These are the top rated real world Java examples of java.io.Math.floor extracted from open source projects. You can rate examples to help us improve the quality of examples.