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
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
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Here is the code to add to your Java program to find the floor and ceiling of four numbers For loop to get users doubles for int i 0 i numberslength i ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started