numRound numCeil numFloor coderinme

numRound numCeil numFloor coderinme

Write a java program ‘MyNumber.java” that performs following operations on a variable ‘num’ of type double:
a) Finds the round value of ‘num’ and stores the result in a variable numRound of type double.
b) Finds the ceil value of ‘num’ and stores the result in a variable numCeil of type double.
c) Finds the floor value of ‘num’ and stores the result in a variable numFloor of type double
d) Cast ‘num’ to type int and stores the result in a variable numInteger of type int.
Display output of numRound, numCeil, numFloor and numInteger on screen.
Program:

import java.io.*;
public class Q8 
{
public static void main(String[] args) throws IOException 
{
BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));
double num,numRound,numCeil,numFloor;
int numInteger;
System.out.print("Enter The value of number for round: ");
num = Double.parseDouble(inp.readLine());
numRound = Math.round(num);
numCeil = Math.ceil(num);
numFloor = Math.floor(num);
numInteger = (int)num;
System.out.println("The value of numround :"+numRound);
System.out.println("The value of numceil :"+numCeil);
System.out.println("The value of numfloor :"+numFloor);
System.out.println("The value of numinteger :"+numInteger);
}
}

For more programs on Java, visit our Java Archives

numRound numCeil numFloor

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme

Leave a reply:

Your email address will not be published.