I am working on a code that adds numbers in an array together and makes the sum. However, if a number is 13, that number and the number after it are skipped. I cannot get my main() method to input parameters into the method that I created to do this task however.
The syntax I have currently is:
public static int sum13(int[] nums) {
int sum = 0;
for (int i = 0; i < nums.length; i++) {
if (nums[i] ==13 || nums[i]-- == 13) {
continue;
} else {
sum += nums[i];
}
return sum;
}
}
public static void main(String[] args) {
System.out.println(sum13([1, 2, 2, 1]));
System.out.println(sum13([13, 1, 2, 13, 3, 3]));
}
}
On the System.out.println lines, I am getting the error message,
The method sum13(int[]) in the type A3 is not applicable for the arguments (int, int, int, int)
Does anyone know how to resolve this error?