Counting loop iterations

Observe the following coding in java and find how many times will PorkyPig printed??

1
2
for(char i='a';i<='z';i++);
    System.out.println("PorkyPig");

26 times Error!! 0 times 1 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.

1 solution

Sonali Srivastava
Jul 21, 2014

There is a semicolon after for loop indicating that next line is not a part of the loop hence after for loops finishes its execution,next line executes for once.

exactly! correct

Chaitnya Shrivastava - 6 years, 10 months ago

it runs based on the character code which is nothing but unicode of char.

Shahid Champ - 6 years, 9 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...