Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Calculus Early Transcendentals

Authors: William L. Briggs, Lyle Cochran, Bernard Gillett

2nd edition

321954428, 321954424, 978-0321947345

More Books

Students also viewed these Programming questions

Question

Explain the importance of staffing in business organisations

Answered: 1 week ago

Question

What are the types of forms of communication ?

Answered: 1 week ago

Question

Explain the process of MBO

Answered: 1 week ago

Question

Evaluate the following integrals. (36 - 9x 2 ) -3/2 dx

Answered: 1 week ago