Computer Science, asked by drake791, 22 hours ago

Initialize an array number[] by the following values:3.52, 5.96, 2.9, 1.06, 4.28, 3.13
Write a program in java that rounds off each number to the nearest integer
(provide the full program)

Answers

Answered by SurajBrainlyStarz
3

Answer:

Use the round(), floor() and ceil() static methods in the Math class. round() will round to the nearest integer, whilst floor() will round down and ceil() will round up.

float f = 9.3f;

Math.round(f); //Output is 9

Math.ceil(f); //Output is 10

Math.floor(f); //Output is 9

You may also be able to just cast the number to int:

int i = (int) 9.3f;

Similar questions