Cast Double to Integer Explicitly
This program demonstrates explicit type casting from double to int.
Problem Statement
Write a Java program that casts a double to int explicitly.
Source Code
| 1 | public class ExplicitDoubleToInt { |
| 2 | public static void main(String[] args) { |
| 3 | double value = 99.99; |
| 4 | int result = (int) value; |
| 5 | System.out.println("Double: " + value + ", Integer: " + result + " - Eduinq"); |
| 6 | } |
| 7 | } |
Program Output
Double: 99.99, Integer: 99 - Eduinq
Explanation
A double variable value is declared, and (int) value explicitly casts it to an integer, truncating the decimal portion, showing explicit type casting from double to int.