【发布时间】:2019-05-22 17:49:43
【问题描述】:
使用“for each”循环将二维数组转换为整数时遇到问题
import java.util.Scanner;
公共类矩阵{ 公共静态 void main(String[] args) {
Scanner userInput = new Scanner(System.in);
int [][] matrix = new int[2][2];
for (int x = 0 ; x < 2 ; x++){
for(int y = 0 ; y < 2 ; y++){
System.out.printf("enter a number for row %d column %d : ",(x+1),(y+1));
matrix[x][y] = userInput.nextInt();
}
}
for(int t : matrix){
System.out.print(t + " ");
}
userInput.close();
}
}
但我得到一个错误 int[] cannot be convert to int.
【问题讨论】:
-
对于这样的问题,你需要提供潜在的输入和对应的预期输出。
-
始终为您的代码使用正确的格式并详细说明问题。提及您面临的问题是什么,就像@DerekPendleton 提到的那样,必须正确提及您期望的输出。
标签: java arrays multidimensional-array