int无法转换为int [] [英] int cannot be converted to int []

查看:310
本文介绍了int无法转换为int []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里编程的新手并且我不断收到错误信息,'不兼容的类型,int无法转换为int []',问题是添加R1&如果R2长度相等,如果没有打印出阵列长度必须相同的消息,如果不重要,不确定哪里出错,任何帮助都会非常感激

new to programming here and i keep getting the error message, 'incompatible types, int cannot be converted to int []', the question is to add R1& R2 together if they are of equal lengths and if not print a message that says 'the arrays must be same length', if that matters, not sure where im going wrong, any help would be greatly appreciated

 public int[] arrayAdd(int[] R1, int[] R2)
{
    int[] sumArray= new int[R1.length];

    if( R1.length!= R2.length)
    {
        System.out.println("The arrays must be same length");
}
else
{
    for(int i=0; i< R1.length; i++)
    for (int j=0; j<R2.length; j++)

    {

        sumArray= R1[i]+ R2[j]; // Error
    }
}
    return sumArray;
}


推荐答案

           sumArray[i]= R1[i]+ R2[j]; // updated line

你需要分配给一个数组元素,但是你做错了。

you need to assign to an array element, but you were doing it wrong.

这篇关于int无法转换为int []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆