The floor function maps a real number to the nearest integer in the downward direction. The ceiling
Question:
The floor function maps a real number to the nearest integer in the downward direction. The ceiling function rounds a real number to the nearest integer in the upward direction.
The notation for floor is floor(x) = ⌊x⌋
For example, ⌊4.32⌋=4 and ⌊4⌋=4. The floor function also rounds negative numbers to the nearest integer in the downward direction: ⌊−4.32⌋=−5 and ⌊−4⌋=−4.
The notation for ceiling is ceiling(x) = ⌈ x⌉
For example,
⌈4.32⌉=5 and ⌈4⌉=4. The ceiling function also rounds negative numbers to the nearest integer in the upward direction: ⌈−4.32⌉=−4 and ⌈−4⌉=−4.
EXAMPLE INPUT (the program should prompt the user to input the below values - these are example values only):
Enter four real numbers, separated by a space: 1.1 3.6 6.7 2.1
CORRESPONDING OUTPUT:
The Floor of each is: 1.0 3.0 6.0 2.0
The Ceiling of each is: 2.0 4.0 7.0 3.0
CODE TO ADD ONTO:
import java.util.Scanner;
import java.util.*;
import java.lang.Math;
public class Lab4 {
public static void main(String args[]) {
// declare variables for user input:
double userInput;
// Prompt to enter 4 doubles:
Scanner scnr = new Scanner(System.in);
System.out.print("Enter four real numbers, separated by a space: ");
double[] numbers = new double[4]; // List of doubles specified by the user
// 'For' loop to get user's doubles:
{
YOUR CODE HERE
}
// print floor and ceiling of each input (use a 'for' loop for each):
// Floor syntax: System.out.print(Math.floor(numbers[i]));
// Ceiling syntax: System.out.print(Math.ceil(numbers[i]));
YOUR CODE HERE
}
}
Calculus Early Transcendentals
ISBN: 978-0321947345
2nd edition
Authors: William L. Briggs, Lyle Cochran, Bernard Gillett