Whole or decimal
Choosing the right data type is crucial in Java - it affects both accuracy and memory usage. Numbers with decimal points need different types than whole numbers. Let's practice making the right choice!
This exercise is part of the course
Introduction to Java
Exercise instructions
- Choose the correct primitive type for
dressPriceandshoePricevariables.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
class WholeOrDecimal {
public static void main(String[] args) {
byte dressSize = 8;
float shoeSize = 11.5F;
// Choose the correct primitive type
____ dressPrice = 55;
____ shoePrice = 49.9;
}
}