How many times is 2 printed?

Given the code fragment:
<code>
public static void main(String[] args) {
String [] table = {“aa”, “bb”, “cc”};
int ii = 0;
for (String ss:table) {
while (ii < table.length) {
System.out.println (ii);
ii++;
break;
}
}
</code>
How many times is 2 printed?

Given the code fragment:

public static void main(String[] args) {
String [] table = {"aa", "bb", "cc"};
int ii = 0;
for (String ss:table) {
while (ii < table.length) {
System.out.println (ii);
ii++;
break;
}
}

How many times is 2 printed?

A.
zero

B.
once

C.
twice

D.
thrice

E.
it is not printed because compilation fails

Explanation:

The outer loop will run three times, one time each for the elements in table.
The break statement breaks the inner loop immediately each time.
2 will be printed once only.
Note: If the line int ii = 0; is missing the program would not compile.



Leave a Reply 16

Your email address will not be published. Required fields are marked *


Google

Google

Although sites we backlink to below are considerably not connected to ours, we really feel they are truly worth a go by, so have a look.

doktor

doktor

here are some links to internet sites that we link to since we believe they’re worth visiting

Fenster und Turen

Fenster und Turen

the time to study or go to the content material or web-sites we have linked to below the

SEO services in Lahore

SEO services in Lahore

although internet websites we backlink to below are considerably not connected to ours, we feel they may be in fact really worth a go through, so possess a look

new

new

just beneath, are many completely not associated web sites to ours, however, they’re surely really worth going over

app maker

app maker

we like to honor several other online web sites on the web, even if they arent linked to us, by linking to them. Under are some webpages worth checking out

Free Games downloads

Free Games downloads

Here are a few of the internet sites we advise for our visitors

PC Games Download

PC Games Download

please check out the web-sites we stick to, which includes this a single, as it represents our picks in the web

how to create your own app

how to create your own app

very few web sites that come about to become comprehensive below, from our point of view are undoubtedly very well really worth checking out

Cash for car

Cash for car

although websites we backlink to beneath are considerably not associated to ours, we really feel they may be truly really worth a go as a result of, so possess a look

Fenster

Fenster

Wonderful story, reckoned we could combine a few unrelated data, nevertheless truly really worth taking a appear, whoa did 1 master about Mid East has got much more problerms at the same time

image

image

check below, are some absolutely unrelated web-sites to ours, even so, they are most trustworthy sources that we use

Xbox 360

Xbox 360

one of our visitors recently encouraged the following website

UPC Shop Innsbruck Hall

UPC Shop Innsbruck Hall

very few internet sites that transpire to become comprehensive below, from our point of view are undoubtedly well worth checking out

prefab houses manufacturers

prefab houses manufacturers

here are some hyperlinks to sites that we link to simply because we consider they are worth visiting