Ends in 7 days

BLACK FRIDAY: Receive 83% off Programiz PRO

+🎁 Buy 1 year, gift 1 year FREE — Split with a friend for just $49.50 each

Start FREE trial →
Background Image

Buy 1 year, Gift 1 year —completely FREE

Start FREE trial →
Zeenat Bibi
last year
Zeenatcountry asked

In double, can we use both int and floating-point data types?

Kelish Rai
Expert
last year
Kelish Rai answered

Yes, a double in Java can store both whole numbers (integers) and decimal numbers (floating-point values).

For example:

// Store an integer
double num1 = 10;

// Store a decimal number
double num2 = 10.5;

Note that even though 10 is an integer, Java automatically converts it to 10.0 when stored in a double variable.

Java
This question was asked as part of the Learn Java Basics course.