Given the code fragment:
Which "for" loop produces the same output?
Given the code fragment:
Which "for" loop produces the same output?
The given while loop initializes x to 0 and prints x while incrementing it until x is less than 10. This means it prints the numbers 0 to 9. Option B is the only answer that initializes the variable, checks the condition before each iteration, and increments the variable after printing, resulting in the same output: 0 to 9.
b is correct A-> not compile miss declaration B-> print 0-9 => ok C-> print 0-10=> not valid D-> print 1 10=> not valid
C) is not compiled
c) it will compile
answer : B A) not compiled initialization part should be missed or be a valid java statement B) correct >0123456789 C) not compiled (there is no conditional part) D) not right ++ operator as prefix returns us : >12345678910
C compile, in for nothing clause is required, the bad thing with this is that print 10, so requiered es print 0,9