遍歷數組中的每個元素,元素之間用空格隔開


package com.itheima.test;
/創建一個長度為6的整數數組,數組中有六個整數(直接賦值即可)。
遍歷數組中的每個元素,元素之間用空格隔開。比如:數組為:{1,2,3,4,5}
打印結果:1 2 3 4 5
/

public class Test11 {
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4, 5, 6};
for (int i = 0; i < arr.length; i++) {
int j = arr[i];
if (j != arr.length) {
System.out.print(j + " ");

        } else {
            System.out.print(j);
        }

    }

}

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM