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
An integer variable num is declared, and assigning it to a double variable result triggers automatic (implicit) widening conversion, showing implicit type casting in Java.