adplus-dvertising
frame-decoration

Question

What is the output of the below Java program with a decrement operator and WHILE-loop?
int a=4;
while(a>0)
{
 System.out.print(a + " ");
 a--;
}

a.

4 3 2 1

b.

3 2 1

c.

Compiler error

d.

None of the above

Posted under Java Programming

Answer: (a).4 3 2 1

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of the below Java program with a decrement operator and WHILE-loop?