Unit 6 Application FRQ
public class ArrayMethods {
private int[] values = {0, 1, 2, 3, 7, 8, 3, 26, 73, 26, 75, 90};
public void printElements(){
for(int i = 0; i < values.length; i++){
System.out.println(values[i]);
}
}
public void swapElements(){
int last = values[values.length-1];
values[values.length-1] = values[0];
values[0] = last;
}
public void evenToZero(){
for(int i = 0; i < values.length; i++){
if (values[i] % 2 == 0){
values[i] = 0;
}
}
}
public static void main(String[] args){
System.out.println("swapping the first and last elemnt");
ArrayMethods swapElements = new ArrayMethods();
swapElements.swapElements();
swapElements.printElements();
System.out.println("replacing elements with 0");
ArrayMethods evenToZero = new ArrayMethods();
swapElements.evenToZero();
swapElements.printElements();
}
}
ArrayMethods.main(null);