Print Integer Cast to Double
This program demonstrates type casting from int to double.
Problem Statement
Write a Java program that casts an integer to double and prints it.
Source Code
| 1 | public class IntToDouble { |
| 2 | public static void main(String[] args) { |
| 3 | int num = 50; |
| 4 | double d = (double) num; |
| 5 | System.out.println("Integer: " + num + ", Double: " + d + " - Eduinq"); |
| 6 | } |
| 7 | } |
Program Output
Integer: 50, Double: 50.0 - Eduinq
Explanation
An integer variable num is declared, and (double) num explicitly casts it to a double, after which both values are printed, showing explicit type casting from int to double.