Well, you could do something like this, but it's nasty as hell. Assuming 4 is max.
int dim = input.nextInt(); //4
Object wtfarray = getArray(dim,2);
putAvalueOnFirstJustForFun(wtfarray,dim,-99);
//throw new Exception("Please kill me");
/*wtfarray
[[[[-99, 0], [0, 0]], [[0, 0], [0, 0]]],
[[[0, 0], [0, 0]], [[0, 0], [0, 0]]]]
*/
//...
void putAvalueOnFirstJustForFun(Object array, int dim, int value)
{
switch(dim)
{
case 1: {((int[])array)[0] = value; return;}
case 2: {((int[][])array)[0][0] = value; return;}
case 3: {((int[][][])array)[0][0][0] = value; return;}
//...until your max
default: {((int[][][][])array)[0][0][0][0] = value;}
}
static Object getArray(int dimensions, int size)
{
switch (dimensions)
{
case 1: {return new int[size];}
case 2: {return new int[size][size];}
case 3: {return new int[size][size][size];}
//...until your max
default: {return new int[size][size][size][size];}
}
}
This thing is ugly, please do not do it.