It looks like you’re making good progress. One problem that jumps out is that you’re thinking of the second expression in a for loop as “stop when this is true.” So you’re thinking:
for (int i = -10; i == 10; i++) {
will keep looping until i == 10 is true. But in fact, it’s “keep looping while this is true.” So it will never loop, because i starts at -10 and then the condition i == 10 is checked, found to be false, and the loop never runs.
So we want to formulate that condition differently:
for (int i = -10; i < 10; i++) {
// ---------------^^^^^^
Now it runs while i < 10. When i is 10, it stops, because i < 10 is no longer true.
This is true of your other loops as well.
1
solved Having trouble converting Python code to Java [closed]