I’m taking a Pre-AP Comp Sci class and figured I join the club and when doing some practice problems online, I stumbled on this question:
Write a program that will print out every number within the range 500 to 1000 that is divisible by 7. You will need to use mod (
%) for this problem.”
I was able to get all other similar problems solved with little or no issue but this one I can’t seem to get. I’m thinking the issue would would be in my for loop at the x % 7 part.
Here’s what I’ve gotten as far as code:
class javaRunner {
public static void main(String[] args) {
for(int x = 500; x <= 1000; x % 7) {
System.out.println(x);
}
}
}
`
The general form of the for statement can be expressed as follows:
x%7 doesn’t make any change on x. Correct way to do this would be,