【发布时间】:2016-07-10 04:10:14
【问题描述】:
public class ArrayFns {
public static void main(String[] args)
{final int AR_SIZE = 10;
banner();
// create two arrays
double[] dvals = { 3.14, 77.56, -7.0, 203.09 }; // initialize array
double[] dvals2 = new double[8];
int[] ivals = new int[AR_SIZE];
System.out.print("\n\nivals -> ");
printAr(ivals);
System.out.print("reverseIt_print ivals -> ");
reverseIt_print(ivals);
private static void reverseIt_print(int[] ivals)
// print the series of int numbers in reverse order
{
int[] d = new int[ivals.length];
for (int i = 0; i < ivals.length / 2; i++) {
d[i] = ivals[i];
ivals[i] = ivals[ivals.length - 1 - i];
ivals[ivals.length - 1 - i] = d[i];
}
System.out.println(d);
}
}
【问题讨论】:
-
System.out.println(d);这不是你打印数组的方式 -> What's the simplest way to print a Java array? -
为什么将数组的长度除以 2?
-
我的 anwser 是否帮助您解决了 Gustavo Bruno 的问题?
-
您应该稍微清理一下该代码。 Camel case 和snake case,缩写的方法名,违反单一职责原则。。当你的代码让我眯眼时,很难提供帮助。
-
是的。我的问题解决了。谢谢大家。我真的很难找到反向数组的解决方案。
标签: java