1.这两个副本应该在一个for循环中完成。 2.输出应在单独的循环中进行。输出应在每个阵列上为每个数字显示5行,如下所示。 “ARRAY1 [index] = xx ARRAY2 [index] = XX ARRAY3 [index] = XX”Array3应包含第一个数组但反转(5-1)。
public static void main(String[] args)
{
// Constants Section
final int FIVE = 5;
final int ONE = 1;
// Variable Declaration Section
int[] firstArray = {1,2,3,4,5};
int[] secondArray;
int[] finalArray;
int i;
// Variable Initialization Section
secondArray = new int[FIVE];
finalArray = new int[FIVE];
// Code Section
for (i = 0; i <FIVE; i++)
{
secondArray = firstArray;
finalArray = firstArray;
}
for (i = FIVE - 1; i >= 0; i--)
{
System.out.println("Array1 = " + firstArray[i] + " Array2= " + secondArray[i] + " Array3= " + finalArray [i]);
}
}
}
请帮助,即时高中学生完全无关紧要的编程。 (简单的更好)
答案 0 :(得分:1)
我认为这就是你所需要的!
public static void main(String[] args)
{
// Constants Section
final int FIVE = 5;
final int ONE = 1;
// Variable Declaration Section
int[] firstArray = {1,2,3,4,5};
int[] secondArray;
int[] finalArray;
int i;
// Variable Initialization Section
secondArray = new int[FIVE];
finalArray = new int[FIVE];
// Code Section
for (i = 0; i <FIVE; i++)
{
secondArray[i] = firstArray[i];
finalArray[i] = firstArray[FIVE-i-1];
}
//For Printing you can loose any logic. This would print in the reverse order but if you want your could change the loop
for (i = FIVE - 1; i >= 0; i--)
{
System.out.println("Array1 = " + firstArray[i] + " Array2= " + secondArray[i] + " Array3= " + finalArray [i]);
}
}
}
我认为应该这样做,如果我误解了,请纠正我。