class Main {
public static void main() {
int[] array = new int[5] {1,2,3,4,5};
}
}
Asked
Active
Viewed 1,130 times
-1

deHaar
- 17,687
- 10
- 38
- 51

Kundan Kumar
- 13
- 5
-
you are basically doing it twice. try int[] array = {1,2,3,4,5}; – Stultuske Oct 11 '19 at 10:21
-
4You're not supposed to give the array size when initializing with values. – Kayaman Oct 11 '19 at 10:22
-
If you check error in eclipse it directly says that 'Cannot define dimension expressions when an array initializer is provided'. Initialize it without size. – Coma Oct 11 '19 at 10:32
1 Answers
1
public static void main(String[] args) {
int[] array = new int[] {1,2,3,4,5};
}
}
You are currently declaring the size of the array twice, the above will work.

Deane Kane
- 126
- 2
- 15