Menu
Topics Index
...
`

Number Test - Java Example Program


Number Test
class NumberTest
{
    public static void main(String arg[])
    {
        Integer i = new Integer(123456);
        Float f = new Float(789);
        Double d = new Double(3456);
        Long l = new Long(654321);
        
        System.out.println("Integer i value is converted into Byte : " + i.byteValue());
        System.out.println("Float f value is converted into Double : " + f.doubleValue()); // LINE A
        System.out.println("Long l value is converted into Float : " + l.floatValue()); // LINE B
        System.out.println("Integer i value is converted into Long : " + i.longValue()); // LINE C
        System.out.println("Float f value is converted into Short : " + f.shortValue());
    
    }
}
OUTPUT

Integer i value is converted into Byte : 64
Float f value is converted into Double : 789.0
Long l value is converted into Float : 654321.0
Integer i value is converted into Long : 123456
Float f value is converted into Short : 789

DESCRIPTION

In this program, we are converting an input required data type into specified data type.

THINGS TO TRY
  • In LINE A replace f by i and see the result which converts Integer into Double.
  • At LINE B replace l by i and see the result which converts Integer into Float.
  • In LINE C replace i by d and see the result which converts Double into Long.

© meritcampus 2019

All Rights Reserved.

Open In App