public static void Reversed (int[] array){
for (int i = 0; i < array.length / 2; i++){
int temp = array[i];
array[i] = array[array.length - (1 + i)];
array[array.length - (1 + i)] = temp;
}
}
public static void Squared (int[] array){
for (int i = 0; i < array.length; i++){
array[i] = array[i] * array[i];
}
}
public static void main (String[] args){
int[] list = new int[5];
for (int i = 0; i < list.length; i++)
list[i] = (int) (Math.random() * 1001);
System.out.println ("The original set is " + Arrays.toString(list) + ".");
System.out.println ("\nThe largest number is " + Max(list) + ".");
System.out.println ("The smallest numer is " + Min(list) + ".");
Reversed(list);
System.out.println ("The reversed array is " + Arrays.toString(list) + ".");
Squared(list);
System.out.println ("The array squared is " + Arrays.toString(list) +
".");
}
The methods work as they are supposed to, but the output reverses the squared numbers too, even though they are not supposed to be reversed. The squared set is supposed to be the same order as the original randomly generated set. I tried putting the Squared method ahead of the Reversed method, but it did not have any affect. Is there a way to make a method "self-contained" of sorts?
Thanks in advance!!!