//Loop through and print out all even numbers from the numbers list in the same order
//they are received. Don't print any numbers that come after 237 in the sequence.
public class excercise4 {
public static void main(String[] args) {
int[] numbers = {
951, 402, 984, 651, 360, 69, 408, 319, 601, 485, 980, 507, 725, 547, 544,
615, 83, 165, 141, 501, 263, 617, 865, 575, 219, 390, 984, 592, 236, 105, 942, 941,
386, 462, 47, 418, 907, 344, 236, 375, 823, 566, 597, 978, 328, 615, 953, 345,
399, 162, 758, 219, 918, 237, 412, 566, 826, 248, 866, 950, 626, 949, 687, 217,
815, 67, 104, 58, 512, 24, 892, 894, 767, 553, 81, 379, 843, 831, 445, 742, 717,
958, 609, 842, 451, 688, 753, 854, 685, 93, 857, 440, 380, 126, 721, 328, 753, 470,
743, 527};
for (int i=0; i < numbers.length; i++) {
int el = numbers[i];
if (el >= 237) break;
if (el%2==0) // using the remainder operator %
System.out.print(el+" "); // the Expected Output likes it like this!
}
}
}
-6
A
回答
1
而是具有:
if (el >= 237) break;
有:
if (el >= 237) continue;
+0
非常感謝你 – 2014-09-25 16:12:54
2
你可能想改變這一行:
if (el >= 237) break;
這一個
if (el >= 237) continue;
因爲break
句子會從整個循環中出去。而continue
將轉到下一個陣列元素。
+0
非常感謝你 – 2014-09-25 16:14:07
+0
@KevinGleeson不要忘記接受任何答案,所以我們可以知道它已經解決了。 – Frakcool 2014-09-25 16:14:44
相關問題
- 1. 打印偶數的循環?
- 2. 打印出偶數
- 3. while循環來獲得偶數列表
- 4. 無法獲得數組打印在c
- 5. 無法打印使用循環
- 6. 使用while循環打印一系列的偶數和奇數
- 7. 僅打印偶數
- 8. 打印無符號整數數組和退出循環
- 9. 循環以相反的順序打印出從2到100的偶數
- 10. 無法獲得用JavaScript打印的值?
- 11. BeautifulSoup4無法獲得打印權。 Python3
- 12. 我無法獲得msqli_result打印
- 13. 無法獲得循環正常工作
- 14. for循環中的打印函數的語法無效
- 15. 無法打印偶數和奇數異步
- 16. 無法做計算並獲得打印出標記
- 17. 打印出循環中的值
- 18. 使用循環打印出三角形
- 19. Perl循環沒有打印出字符
- 20. Java嵌套for循環打印出
- 21. 多次循環打印輸出
- 22. while循環打印兩次輸出
- 23. 使用For循環打印出元音
- 24. 無限循環打印列表
- 25. 打印循環終值循環打印其內容
- 26. 獲得一個循環以停止VBA中的打印
- 27. 無法打印出我的輸出語句一次沒有循環
- 28. javascript循環完成後循環打印
- 29. 雖然循環偶數
- 30. 如何在高斯循環內打印運行計數
'break'是做什麼的?數組中索引0處的元素是什麼? – 2014-09-25 16:09:13