Java Program to convert int type variables to double

Example 1: Java Program to Convert int to double using Typecasting

class IntToDouble {
  public static void main(String[] args) {

    // create two int variables
    int a =99;
    int b =49;

    // convert int into double using typecasting
    double c = a;
    double d = b;

    System.out.println(c);   
    System.out.println(d);   
  }
}
Output
99.0
49.0

Example 2: Convert int to object of Double using valueOf()

class IntToDouble{
  public static void main(String[] args) {

    // create a int variables
    int a = 334;

    // convert to an object of Double using valueOf()
    Double obj = Double.valueOf(a);

    System.out.println(obj);    
  }
}
Output
334.0

Leave a Reply