我试图用“-1”作为所有值填充二维数组。我正在使用的代码是:
int c [] []=new int[4][4];
Arrays.fill(c,-1)
这会引发以下错误:
Exception in thread "main" java.lang.ArrayStoreException: java.lang.Integer
谁能告诉我代码中有什么问题吗?
最佳答案
它是一个整数数组的数组。
你应该写
int c [] []=new int[4][4];
for(int[] arr : c){
Arrays.fill(arr,-1);
}
关于Java Arrays.fill() 负数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13598343/