import java.util.Arrays;
class Main {
public static void main(String[] args) {
//create an array with 10 elements
int[] intArray = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int evenTotal=0, oddTotal=0;
//remove element "40"
int target=3;
//create a copy to hold the new values (1 shorter of course)
int[] copy = new int[intArray.length - 1];
for (int i = 0, j = 0; i < intArray.length; i++) { //begin i and j at 0
if (i != target) { //copy everything as long as i doesnt match target
copy[j++] = intArray[i]; //fill position of j with element of i
}
}
//print entire array without for loop (must import java.util.Arrays)
//System.out.println("Original" + Arrays.toString(intArray));//original
//System.out.println("Modified" + Arrays.toString(copy)); //modified
//print all even numbers
for(int i=0; i<copy.length; i++){
if(copy[i]%2 == 0){
evenTotal+=copy[i];
System.out.print(" "+copy[i]);
}
}
System.out.println(" = "+ evenTotal);
for(int i=0; i<intArray.length; i++){
if(intArray[i]%2 != 0){
oddTotal+=intArray[i];
System.out.print(" "+intArray[i]);
}
}
System.out.println(" = "+oddTotal);
//Yes, you can do it again following the same principals...
int[] copy2 = new int[copy.length - 1];
int target2 = 2;
for (int i = 0, j = 0; i < copy.length; i++) {
if (i != target2) {
copy2[j++] = copy[i];
}
}
//System.out.println("Original" + Arrays.toString(copy));
//System.out.println("Modified" + Arrays.toString(copy2));
}
}