Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 数组(toString)输出不正确_Java - Fatal编程技术网

Java 数组(toString)输出不正确

Java 数组(toString)输出不正确,java,Java,事实上,这一步是从另一步开始的。没有足够的字符继续。无论如何问题是输出是110223329。尽管我可以为数组值10、23、29返回字符串,并使用字符串引用作为1、2和3。我的问题是,是否可以返回索引值1、2、3和以及数组值。我说的有道理吗。这就是我所做的 // int[] groups = {10, 23, 29}; in the constructor String tempA = ""; String tempB = " "; int[] temp = new int[4]; int l

事实上,这一步是从另一步开始的。没有足够的字符继续。无论如何问题是输出是110223329。尽管我可以为数组值10、23、29返回字符串,并使用字符串引用作为1、2和3。我的问题是,是否可以返回索引值1、2、3和以及数组值。我说的有道理吗。这就是我所做的

// int[] groups = {10, 23, 29}; in the constructor

String tempA = "";
String tempB = " ";

int[] temp = new int[4];
int length = groups.length;

for (int j = 0; j < length; j++)
{
  temp[j] = groups[j];
  tempB = tempB + "("+goups+")";
}

groups = temp;
Arrays.sort(coingroups);

for(int i = 1; i < groups.length;i++)
{
  tempA = tempA+"  "+(i)+ "("+groups[i]+")";
}
return tempA;

使用下面的代码,您将创建一个字符串,该字符串表示整个数组。然而,仅仅使用数组“组”将更难处理

 // int[] groups = {10, 23, 29}; in the constructor
 String tempA = "";
 for (int j = 0; j < groups.length; j++)
 {
  tempA = tempA + "  " + j + " (" + groups[j] + ") ";
 }
 return tempA;

如果您创建了一个地图,并将数据保存在其中,您可以获得所需的任何信息。比如:

Map<Integer, String> stack = new HashMap<Integer, String>();
stack.put(1, "10");
stack.put(2, "23");
stack.put(3, "29");

好的预期输出示例是什么?@dowln:您希望它输出什么?您是否已经返回了索引值和数组值-110 223 329。具体来说,您希望打印出什么?您希望您的输出是什么样的?不要用文字来解释,给我们展示一个输出110 223 329的例子。记住,我得到了这个输出,但我不确定是否有可能得到一个表示整个数组的字符串:索引和数组。
stack.get(1) will return "10"
stack.get("10") will return 1