+ 4
Why does my output keep printing?
I know it's in a for loop but I'm wondering how to stop it. I finished it but with a lot of help. https://code.sololearn.com/c2JyX7EXoPtZ/?ref=app
6 Antworten
+ 10
You want your code to print the output just once, right? Use the unlabeled 'break' statement to terminate the loop as soon as the desired String is printed once!
if (boxes[x] < 10 || boxes[x] > 20) {
System.out.println("The location of the blackbox is at "+ blackboxposition + " and weighs "+ blackboxone + " kg");
break;
}
For more information, refer:
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html
+ 2
https://code.sololearn.com/WJ9QOJ0fEXTj/?ref=app Here's a reference
+ 1
the code is ok and the loop is limited, but the int array is to big for server processing time limit.Try to reduce the int array max for 73 items.This is the timetout limit.Here is the fixed code to try.
https://code.sololearn.com/cpx5eWozF4mQ/?ref=app
0
thank you and i appreciate you taking time to help me out, however I'm looking for the output just to be one statement not a continuous repeat.
0
thank you too, I didn't know you could apply break to a for loop. Have a great everyone
0
ok,I did understand the problem properly.The brake is correct solution;)