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

double value = 99.99; Declares double. (int) value Explicitly casts to int, truncating decimals. Conclusion: Shows explicit type casting from double to int.

Quick Links to Explore