在Java中,可以使用以下方法來初始化數組并賦值:
int[] numbers = {1, 2, 3, 4, 5};
String[] names = {"Alice", "Bob", "Charlie"};
int[] numbers = new int[5];
for (int i = 0; i < numbers.length; i++) {
numbers[i] = i + 1;
}
int[] numbers = new int[5];
Arrays.fill(numbers, 0); // 將數組所有元素的值設置為0
int[] numbers = {1, 2, 3, 4, 5};
Arrays.sort(numbers); // 對數組元素進行排序