Cast Integer to Double Automatically
This program demonstrates automatic type casting from int to double.
Problem Statement
Write a Java program that shows automatic casting from int to double.
Source Code
| 1 | public class AutoIntToDouble { |
| 2 | public static void main(String[] args) { |
| 3 | int num = 20; |
| 4 | double result = num; // automatic casting |
| 5 | System.out.println("Integer: " + num + ", Double: " + result + " - Eduinq"); |
| 6 | } |
| 7 | } |
Program Output
Integer: 20, Double: 20.0 - Eduinq
Explanation
int num = 20; Declares integer. double result = num; Automatically casts int to double. Conclusion: Shows implicit type casting in Java.