16.3k views
3 votes
What output is generated by this for loop?

String str = "";

for (int i = 0; i <= str.length() - 1; i++)

{

System.out.println(str.charAt(i) + "-");

}


Group of answer choices


---


No output is generated.


--


-

User ArtK
by
4.3k points

1 Answer

6 votes

Answer:

No output is generated

Step-by-step explanation:

(1) The first line initialized an empty string, str

(2) The for loop attempts to iterate through the empty string. Since it is an empty string, no iteration will be done.

This implies that, the print statement within the loop block will not be executed.

Hence:

No output is generated

User Avanthika
by
3.9k points