Menu
Topics Index
...
`

Number Method Test2 - Java Example Program


Number Method Test2
class NumberMethodTest2
{
    public static void main(String arg[])
    {
        Float b = 5.6f;
        System.out.println("Converts to Positive Number : " + Math.abs(-7));
        System.out.println("Smallest integer greater than b : " + Math.ceil(b));
        System.out.println("Greatest integer less than b : " + Math.floor(b));
        System.out.println("Closest integer as double : " + Math.rint(b));
        System.out.println("Closest integer : " + Math.round(b));
        System.out.println("Minimum of two numbers : " + Math.min(12.3, 9.6));
        System.out.println("Maximum of two numbers : " + Math.max(8, 6));
        System.out.println("e power 100 : " + Math.exp(100));
        System.out.println("Log value : " + Math.log(2.7183));
        System.out.println("2 Power 5 : " + Math.pow(2, 5));
        System.out.println("Square root : " + Math.sqrt(81));    
    }
}
OUTPUT

Converts to Positive Number : 7
Smallest integer greater than b : 6.0
Greatest integer less than b : 5.0
Closest integer as double : 6.0
Closest integer : 6
Minimum of two numbers : 9.6
Maximum of two numbers : 8
e power 100 : 2.6881171418161356E43
Log value : 1.0000066849139877
2 Power 5 : 32.0
Square root : 9.0

DESCRIPTION

In this program, abs, ceil, floor, rint, round, min, max, exp, log, pow and sqrt methods are used.

© meritcampus 2019

All Rights Reserved.

Open In App