Learn AP Comp Sci

☰

Problem of the Day

Friday, October 9, 2026


Problem:

A Java program contains the following line of code.

int age = 17.3;

This line is an example of

  1. a syntax error
  2. a run-time error
  3. a logic error
  4. There are no errors in this code.

Show solution:

The correct answer is a. A syntax error is a violation of the "grammar rules" of the language, and in this case, trying to store a floating-point value in an int variable is not allowed.

Syntax errors are typically caught during the process of compiling the source code into bytecode, and are thus sometimes called compile-time errors.