Java中的Int[]数组返回字节。为什么呢?

huangapple 未分类评论46阅读模式
英文:

Java Int[] Array returning bytes. Why?

问题

// 将一个由整数组成的字符串转换为int[]数组
// reversed 是整数字符串的名称

以下是代码部分

public int[] makeIntArray(){
    intArray = new int[reversed.length()];
    for (int i = 0; i < reversed.length(); i++){
        intArray[i] = reversed.charAt(i) - 48;
        System.out.println("int " + i + " is " + intArray[i]);
    }
    System.out.println("IntArray is: " + intArray);
    return intArray;
}

// 每当我运行这段代码时,返回的整数数组是 "cf814a82@I[" 而不是 [3, 3, 8, 2, 3, 8, 2, 8]
英文:

//turns a string of integers into an int[] array
// reversed is the name of the string of integers

Here is the code:

    public int[] makeintArray(){
          intArray = new int[reversed.length()];
          for (int i = 0; i &lt; reversed.length(); i++){
              intArray[i] = reversed.charAt(i) - 48;
              System.out.println(&quot;int &quot; + i + &quot; is &quot; + intArray[i]);
  }
  System.out.println(&quot;IntArray is: &quot; + intArray);
  return intArray;

}

//Whenever I run this I get the integer array returned as "cf814a82@I[" rather than [3, 3, 8, 2, 3, 8, 2, 8]

huangapple
  • 本文由 发表于 2020年4月6日 08:10:03
  • 转载请务必保留本文链接:https://java.coder-hub.com/61051141.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定