-2
我試圖用.length輸入數組的長度,但弄錯了。 什麼是錯的?如何輸入數組長度?
import java.util.*;
public class Storage {
public static int i = 0, size;
static int[] number;
public static void main (String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("What is the value of array?");
number = new int [input.nextInt()];
System.out.println("Write the numbers:");
for (int i : number) {
number[i] = input.nextInt();
}
System.out.println("Array:");
System.out.println(Arrays.toString(number));
}
}
,輸出是:
What is the value of array?
3
Write the numbers:
1
2
3
Array:
[3, 0, 0]
'的for(int i = 0; i
你試過'lengh'或'length'嗎? – alayor
兩者,但沒有結果 – Nina