所有的代码是正确的,除了行,我有数组,并试图打印他们(第5-6行)。如何打印数组?
public class PassedArray {
public static void passingArray(int[] nums) {
int arr[] = {6, 3, 8, 89, 34, 89, 132, 76, 34, 89, 11, 9, 19} ;
System.out.println(nums);
int[] temp = new int[nums.length]; //create temporary array, temp, set the length of it equal to the original array
for(int i = 0; i < nums.length; i++) {
temp[i] = nums[i]; //set every value at temp equal to every number at i
//return nums;
}
int index = 0; //create integer index to keep track of index
for(int i = 0; i < temp.length; i++) {
if(temp[i] % 2 ==0) { //if number at i divided by 2 yields remainder of 0
nums[index] = temp[i]; //set number at index equal to temp at i, because temp at i is even
index++; //Increment of index++ means index will increase by one each loop
//This is done because if this is not done, only the first number will be replaced
}
}
for (int i = 0; index < temp.length; index++) {
if (temp[i] % 2 != 0) { //if number at i divided by 2 does not yield remainder of 0
nums[index] = temp[i]; //add the temp value to nums at index
index++; //Increment of index++ means index will increase by one each loop
}
}
}
}
println(nums)只提供哈希代码。使用Arrays.ToString(nums)
当我打印出 我得到的回报是:
我试图键入数组,但得到 我在谷歌上搜索了一下,我知道了关于这个例外的一切,但是我不能做任何事情来解决这个愚蠢的问题。
嗨,我有这样的东西: 如何打印排序结果?
问题内容: 这是我的数组代码,我需要反向打印。 问题答案: 只需反转for循环的方向即可。现在,它从0到长度开始计数,从长度到0开始计数
问题内容: 我从mysql数据库获取ID和类别名称。 当我警告结果时,我得到: (这是对象吗?) 我如何打印这样的结果: 丹斯基 M \ u0119skie M \ u0119ski-编码错误。应该是 Męskie 。我该如何更改? 问题答案:
运行: