Computer Science, asked by Niveda18, 2 months ago

write a program to input a floating point number and round it off to the nearest integer

Answers

Answered by prathamsp1005
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 dreamgirl245
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