Question: What is the difference between these examples of code? Example 1 ) int count; for ( count = 0 ; count < 1 0 0

What is the difference between these examples of code?
Example 1)
int count;
for (count =0; count <100; count++)
System.out.println("The counter is "+ count);
// assume end of method
Example 2)
for (int count =0; count <100; count++)
System.out.println("The counter is "+ count);
// assume end of method
Group of answer choices
A) Both will work. In Example 1, the scope of the variable count will exist outside of the loop.
B) Both will work. In Example 2, the scope of the variable count will only exist within the loop. This is fine as long we don't need to access variable count outside of the loop.
C) Neither will work because we need always need the braces for a for loop.
D) Both A and B are true

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!