Menu
Topics Index
...
`

Number Method Test1 - Java Example Program


Number Method Test1
class NumberMethodTest1
{
    public static void main(String arg[])
    {
        Integer a = 5;
        Integer b = 6;
        String c = "8";    
        
        System.out.println("Compares two Intergers : " + a.compareTo(b));
        System.out.println("Checks for equal : " + a.equals(b));
        System.out.println("Converts to Float : " + Float.valueOf(b));
        System.out.println("Converts to String : " + Integer.toString(a));
        System.out.println("Converts String to Integer : " + Integer.parseInt(c));
    
    }
}
OUTPUT

Compares two Intergers : -1
Checks for equal : false
Converts to Float : 6.0
Converts to String : 5
Converts String to Integer : 8

DESCRIPTION

In this program, compareTo, equals, valueOf, toString and parseInt<cw> methods are used.

THINGS TO TRY
  • Give b value as 5 and check the output for compareTo and equals.

© meritcampus 2019

All Rights Reserved.

Open In App