Problem of the Day
Tuesday, September 15, 2026
Problem:
Data types commonly used in Java programs include the int, double, and String types. Which of the following declaration/assignment statements would cause an error during compiling?
int age = 17.0;double shoeSize = 14;String weight = "105";
- I only
- II only
- III only
- I and II
- I and III
The correct answer is a.
In statement I, trying to assign a double value to an int variable runs the risk of losing information that might be stored in the digits after the decimal point. In statement II, Java does allow an int value to be referenced by a double variable.
Statement III is legal also, because the 105 is enclosed in double-quotes making it a string value. Although this statement is syntactically correct, it is probably not a good way of storing that data. Numeric values should almost always be placed in int or double variables.