Multiple choice

What is the proper format for assigning a value to a variable?

  1. int 5 = x;

  2. 5 = x int;

  3. int x = 5;

  4. x = 5 int;

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

In Java, variable declaration and assignment must follow the syntax: data type, followed by the variable name, the assignment operator (=), and finally the value. Therefore, 'int x = 5;' is the only syntactically correct option.