0
Can't solve the problem when compiling
Hello. During compilation of one of the tasks I receive an error: java:23: error: variable declaration not allowed here Can't understand where I went wrong and how to fix it. Posted code with my comments: https://code.sololearn.com/c72Sa26qm0pd Thanks for the help
4 Answers
+ 1
You're attempting to use the variable cr prior to it being initialized and also trying to use it beyond its scope. You can't use the variable itself to initialize itself as it has no value. Also when there are no curly braces after an if statements condition Java will use the next statement only within the scope of the if statement. This means that your use of the variable cr in the print statement is out of scope as it was declared within the if block. The code below should fix these 2 issues.
for (int i = 0; i < numArr.length; i++) {
int cr = 0;
if (numArr[i] % k)
cr += numArr[i];
System.out.println("ĐĄŃППа Ńавна" + cr);
}
0
Yes, I understand that the problem in this place. Don't understand what is wrong here.
0
Thanks for the help. with variable Declaration, I understand. Ran into another problem: error: incompatible types: int cannot be converted to boolean
if (numArr[i] % k)
A pointer to %
I understand that inside the parentheses, both variables need to be boolean and nothing else?
0
sorry, found the error, thank you.