java - int[] 不能转换为 int[][]
问题描述
我有一个这样的 int[][] 建立:
public static final int[][] answers
但是我在迭代它时遇到了问题。我有这个:
for(int[][] s : answers)
我收到一条错误消息,提示“不兼容的类型:int[] 无法转换为 int[][]”。它们都是 int[][] 所以我很困惑为什么会这样。
解决方案
在int[][]
中,二维数组的每个元素都是一个整数数组 ( int[]
)。
在您的 for 循环中,您希望遍历 中的每个元素s
,answers
因此每个元素s
都是类型int[]
所以,你需要的是for(int[] s : answers)
,而不是for(int[][] s : answers)
推荐阅读
- reactjs - React 中 Material UI 组件渲染内容的问题
- authentication - Ionic 6 上的身份验证服务出错
- ansible - 如何在 ansible wait_for 模块中打印成功和失败的调试消息以测试防火墙。?
- arrays - 如何在空手道中为 json 数组设置动态值
- python - Azure 函数 Python | 将带有属性的 EventData 消息发送到事件中心输出
- angular - NGXS 调度未调用操作
- google-chrome - WebDriver 问题,我无法打开谷歌浏览器
- mysql - 具有初始枢轴条件的多对多关系
- ssl - Google Cloud TCP 外部负载平衡器和 TLS 未自签名
- r - 按另一个因素重新排序因素水平