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
int num = 50; Declares integer. (double) num Casts integer to double. Prints both values. Conclusion: Shows explicit type casting from int to double.