初級 › 配列の new と初期化子の書き分け › パターン4
配列の new と初期化子の書き分け
new int[3] と {1,2,3} の使い分け。
1 public class Main { 2 public static void main(String[] args) { 3 int[] nums = _________{1, 2, 3}; ^ 4 System.out.println(nums[0]); 5 } 6 }
Main.java:3: error: <identifier> expected
空欄を埋めてビルドを通す
波括弧の初期化子はnewを付けずに書きます。newを付けるなら new int[]{1,2,3} のように型が必要です。
次の問題