Zeenat Bibi
last month
Zeenatcountry asked

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

Kelish Rai
Expert
2 weeks ago
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.