Java 为什么数组是';s长度未更新,是否导致索引越界错误?

Java 为什么数组是';s长度未更新,是否导致索引越界错误?,java,arrays,encryption,Java,Arrays,Encryption,我的2D数组的大小,EncryptedArr,似乎没有在encryptData方法中得到更新 此方法用于将字符串(在主方法中给定)加密到整数数组中。为了查看循环是否确实正确地将数据放入数组,我需要数组的大小与放入数组的数据相匹配 静态无效加密数据(字符串到加密) { stringLength=toEncrypt.length() encryptedArr=新整数[stringLength][stringLength] 对于(rowIndex=0;rowIndexfor)(rowIndex=0;r

我的2D数组的大小,
EncryptedArr
,似乎没有在
encryptData
方法中得到更新

此方法用于将字符串(在主方法中给定)加密到整数数组中。为了查看循环是否确实正确地将数据放入数组,我需要数组的大小与放入数组的数据相匹配

静态无效加密数据(字符串到加密)
{
stringLength=toEncrypt.length()
encryptedArr=新整数[stringLength][stringLength]

对于(rowIndex=0;rowIndex
for)(rowIndex=0;rowIndex for a start)您发布的代码无效。第二次调用
encryptedArr=new int[stringLength][stringLength]
一次,和
stringlength
是你的例子是
1
,而且
行索引数组不能调整大小。你认为代码的哪一部分会这样做?我的错误。自从我上次为数组编写代码以来已经有几个月了,所以我有点生疏,似乎只是犯了一些简单的错误。我想我应该是请耐心等待,并在发布前再检查我的代码几次。很抱歉浪费您的时间。
for (rowIndex = 0; rowIndex <= stringLength; rowIndex++){ //here
    for (columnIndex = 0; columnIndex < encryptedArr[rowIndex].length;columnIndex++){
         while (indexOfString <= stringLength){
          charToEncrypt = toEncrypt.charAt(indexOfString)
          charValue = charToEncrypt;
          encryptedArr[rowIndex][columnIndex] += charValue;
          indexOfString++;
     }
  }