Summing elements in arrays
This code is supposed to find numbers that are multiples of 4 and add them up, and print the total. I get two different errors messages depending on where I decide to have the System.out statement, please look at the code, I placed a comment that shows the different error messages, the error messages point to the variable sum. import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int length = scanner.nextInt(); int[] array = new int[length]; for (int i = 0; i < length; i++) { array[i] = scanner.nextInt(); } //your code goes here int sum = 0; for (int x = 0; x < length; x++){ if (array[x] % 4 = 0 ){ sum += array[x]; } else { sum = sum; } } //System.out.println(sum);**unexpected type } System.out.println(sum); }