+ 1
Why my following code isn't working
Problem: I want to print the 11 as output! My Code: class Abhishek { public static void main(String[] args) { int[][][] sample00 = {{{1, 2}, {3, 4}}, {{5, 6}, {7, 8}}, {{9, 10}, {11, 12}} }; } int x = sample00[2][1][0]; System.out.println(x); }
4 Respuestas
+ 8
All statement lines should be inside the main function.
Move the 'int x' and 'System..' lines up inside the bracket, and it will work.
+ 4
Tibor Santa Actually you can have static initializers outside of any static method. They are useful to initialize static fields without having to call an init() method. Still i would prefer the Singleton approach to that
https://code.sololearn.com/c1MX5yj70465/?ref=app
+ 2
Thanks Giorgos D
I know about static blocks, but I haven't really had any need to use them so far. Anyway I guess the question here is on a more basic level.
0
Solution:
class Abhishek {
public static void main(String[] args) {
int[][][] sample00 = {{{1, 2}, {3, 4}},
{{5, 6}, {7, 8}},
{{9, 10}, {11, 12}}
};
int x = sample00[2][1][0];
System.out.println(x);
}
//int x = sample00[2][1][0];
//System.out.println(x);
}