Computer Science, asked by trishay434, 4 months ago

Find the output

void main()

{

do

{

System.out.println("FRIENDS");

while (true);

}
pls dont spam pls answer ​

Answers

Answered by atrs7391
3

There will be no Output as the program has Syntax Error...

Rectified Program:

void main()

{

do

{

System.out.println("FRIENDS");

}

while (true);

}

Output of the rectified program:

FRIENDS

FRIENDS

FRIENDS

and this will go on and will never stop until and unless it is forcefully stopped.

Answered by DüllStâr
88

Answer:-

Error i.e no output

Explanation :-

The program will not execute

why?

As there is a syntax error

.°. There will be no output

First of all let's review Syntax of do-while loop:-

do

{

//{} can be omitted if there is only one Statement

-----------------

Statements

-----------------

//in this inside the loop only we have to update the value if required

}

wlile(test condition)

so as we can see here condition will be checked outside the loop i.e after currely brackes/paranthese({})

So correct snippet will be:-

void main()

{

do

{

System.out.println("FRIENDS");

}

while (true);

Output:

FRIENDS

FRIENDS

FRIENDS

FRIENDS

FRIENDS

...

...

...

The execution will not stop until and unless external internation occurs and such types of loops are known as infinite loop.

Similar questions