write a program to input a floating point number and round it off to the nearest integer
Answers
Answered by
0
Answer:
》》》》》》 Using Typecasting. (int)(x + 0.5) , and for rounding the negative values, we can use the expression (int)(x - 0.5) , where x is the given floating-point number.
Answered by
0
Answer:
13) Write a program to input floating point integer and round it off to the nearest integer.
import java.util.*;
class RoundOff
{
public static void main(String arr[])
{
Scanner scan=new Scanner(System.in);
float n;
int r;
System.out.println("Enter a floating point number:");
n=scan.nextFloat();
r=(int)(n+0.5f);
System.out.println("Answer="+r);
}
}
Output:-
12.3
12
Explanation:
Similar questions
Biology,
1 month ago
Computer Science,
1 month ago
Biology,
2 months ago
English,
2 months ago
Computer Science,
9 months ago
English,
9 months ago
Math,
9 months ago