write a program to input a floating point number and round it off to the nearest integer for example input
Answers
Answered by
6
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