Print Double Cast to Integer

This program demonstrates type casting from double to int.

Problem Statement

Write a Java program that casts a double to int and prints it.

Source Code

1 public class DoubleToInt {
2 public static void main(String[] args) {
3 double pi = 3.14159;
4 int value = (int) pi;
5 System.out.println("Double: " + pi + ", Integer: " + value + " - Eduinq");
6 }
7 }

Program Output

Double: 3.14159, Integer: 3 - Eduinq

Explanation

double pi = 3.14159; Declares double. (int) pi Casts double to int, truncating decimal part. Prints both values. Conclusion: Shows explicit type casting from double to int.

Quick Links to Explore