How many times the following loop will gets executed? What is the output of the same?

int counter=1;
do
{
System.out.printIn(counter);
} while ( counter ++ < 5 );


Solution



When counter =1:
print:-
1

When counter =2:
print:-
1 2

When counter =3:
print:-
1 2 3

When counter =4:
print:-
1 2 3 4

When counter =5:
print:-
1 2 3 4 5

So output is: 1 2 3 4 5


Contact Us

REACH US

SERVICES

  • CODING
  • ON-LINE PREPARATION
  • JAVA & PYTHON

ADDRESS

B-54, Krishna Bhawan, Parag Narain Road, Near Butler Palace Colony Lucknow
Contact:+ 919839520987
Email:info@alexsir.com