102k views
3 votes
loopCount = 1; while(loopCount < 3) System.out.println("Hello"); loopCount = loopCount + 1; No output Hello Hello Hello Hello Hello This is an infinite loop

2 Answers

4 votes

Answer:

Step-by-step explanation:

wrap the statements of loop in curly braces {} if the statements are more than one. In your case loop counter=loopcounter+1 is out of loop If you want a finite loop then here ist is ffit is iisDo it like this will make it finite loop

int loopCount = 1

while(loopCount < 3) {

System.out.println("Hello");

loopCount = loopCount + 1;

}

User Gary In
by
5.7k points
2 votes

Answer:

You need to wrap the statements of loop in curly braces {} if the statements are more than one. In your case loopcounter=loopcounter+1 is out of loop

Step-by-step explanation:

// Do it like this will make it finite loop

int loopCount = 1

while(loopCount < 3) {

System.out.println("Hello");

loopCount = loopCount + 1;

}

User Wirsing
by
5.8k points