Yo Yo Honey Singh....!!!

Observe the following coding in java. Can you find the number of times "yo yo honey singh" will be displayed?

1
2
3
4
for(int i=0;i--<=5;i++)
     {
           System.out.println("Yo Yo Honey Singh");
      }

Log on to www.comprogzz.in for more such java coding:))

five times infinite times ten times one time

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

3 solutions

Sonali Srivastava
Jul 18, 2014

i is initialized with a value 0 in condition i--<=5 n update is i++ 1st time i=0,(i--) -1<=5 loop executes then i++ makes i=0 but in 2nd execution of the loop i-- again makes i=-1 thus value of i is always -1 due to i-- n 0 due to i++ hence it executes infinitely

Monikrishna Roy
May 22, 2014

first i=0, then for i--, i is -1, then for i++, i is 0

for this i is always 0 and 0<=5 , so , this program print this line infinite times.

I think as it is postfix operator so immediately i-- does not change to -1... i value remains 0 always.. so infinite number of times it will run.

Arijit Banerjee - 7 years ago
Jasveen Sandral
May 23, 2014

It's easy cause she wrote i---------------

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...