157k views
0 votes
Errors can be syntax errors or logic errors (the code works, but not as intended).

Which of the following statements contains an error?

I. String firstInitial = firstName.subString(0,3);
II. String lastName = in.nextLine();
III. String name = firstInitial + ". " + lastName;

I only
II only
III only
I and II only
II and III only

User Draeron
by
4.5k points

1 Answer

6 votes

Answer:

I. String firstInitial = firstName.subString(0,3);

Step-by-step explanation:

I - The first initial should always be the first character and not a substring from 0 to 3. For example the substring 0 to 3 of Daniel would be "Dani" and not "D". So, it is a logic error.

I am assuming the name variable needs to be like "D. lastName" and not "Dani. lastName"

User Phatmann
by
4.3k points