共計 330 個字符,預計需要花費 1 分鐘才能閱讀完成。
要獲取數(shù)組中的某一個值,可以通過數(shù)組的索引來訪問。數(shù)組的索引從 0 開始,依次遞增,直到數(shù)組的長度減 1 為止。例如,要獲取數(shù)組 arr
中索引為 index
的值,可以使用 arr[index]
來訪問。以下是一個示例代碼:
public class Main {public static void main(String[] args) {int[] arr = {1, 2, 3, 4, 5};
int index = 2; // 獲取數(shù)組中索引為 2 的值
int value = arr[index];
System.out.println(" 數(shù)組中索引為 2 的值為: " + value);
}
}
在上面的代碼中,我們定義了一個整型數(shù)組 arr
,然后通過索引 index
獲取了數(shù)組中索引為 2 的值并打印出來。
丸趣 TV 網(wǎng) – 提供最優(yōu)質(zhì)的資源集合!
正文完