java - 类型不匹配:无法从 int 转换为 Integer
问题描述
我正在尝试做一个二维数组。
这是代码: public class TwoDimensionalArray {
public static void main(String[] args) {
Integer str[][]=new Integer[3][3];
str [0][0]=10; the error is here 'cannot convert from int to integer'
解决方案
Integer 和 int 是不同的数据类型。如果您不指定,则该语言假定为 int。我会解决它如下:
public static void main(String[] args) {
Integer str[][]=new Integer[3][3];
Integer myInt = 10;
str [0][0]=myInt;
}
推荐阅读
- html - CSS - 带有溢出省略号的旋转文本
- java - 如何解决:系统服务在 onCreate() 之前对活动不可用?
- css - React-Toolbox:尝试将卡片水平对齐
- javascript - 无法在 React 中渲染一个子组件之前的另一个子组件
- django - 如何从模板内的 ModelMultipleChoiceField 访问对象的字段值?
- openlayers-3 - 如何在 Openlayers 中旋转完整视图?
- arrays - Kotlin - 声明一个变量,它是哈希映射的数组列表,其中键是字符串,值是另一个数组列表
- amazon-web-services - 使用 aws 堆栈集部署 lambda 资源
- jquery - 如果我已经包含更新的版本,是否可以在引导程序中删除 JQuery 3.3.1 的包含?
- javascript - 当用户使用 macbook 触摸板时,猫头鹰轮播滚动到最新元素