Welcome to the World of Online Learning:
Hello Friends “This blog helps you to learn Java programming concepts. You can learn Java language at your own speed and time. One can learn concepts of Java language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”
Write a Java Program to convert int type variables to double
PROGRAM: Java Program to convert int type variables to double
/*Java Program to convert int type variables to double*/
1: Java Program to Convert int to double using Typecasting
class Main {
public static void main(String[] args) {
// create int variables
int a =33;
int b = 29;
// convert int into double
// using typecasting
double c = a;
double d = b;
System.out.println(c); // 33.0
System.out.println(d); // 29.0
}
}
2: Convert int to object of Double using valueOf()
class Main {
public static void main(String[] args) {
// create int variables
int a = 332;
// convert to an object of Double
// using valueOf()
Double obj = Double.valueOf(a);
System.out.println(obj); // 332.0
}
}