79653847

Date: 2025-06-05 05:48:07
Score: 0.5
Natty:
Report link

You don’t need to do anything to exit the if statement. As Anonymous already mentioned in a comment.

I added the variable declarations that are not in the code that you posted in the question and ran your code. A sample session:

1
How many?
2
1
How many?
1
4
Total laptops: 3

As you can see, I also added a statement after the loop to print the result:

    System.out.println("Total laptops: " + laptops);

So your code already works fine.

Your if statement ends at the right curly brace }. And since you have no statements after the if statement (before the curly brace that ends the loop), it then goes back to the top of the loop.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: Marija Beridze