I’m trying to write a program that prints all numbers from 0 to 1,000 where the number mod 5 = 3. This is what I have so far
public class NewMain {
public static void modNumbers(int i)
{
}
public static void main(String[] args) {
for(int i = 0; i > 1000; i++)
{
if(i%5 = 3)
{
System.out.println(i);
}
}
}
}
I’m not getting any output, so I know I’m doing something wrong. Should I have a return type in the method?
Change it from:
to
Essentially, the loop never begins because the loop invariant is false (as i is less than 1000), and your print statement is never reached because the loop never initializes.
Additionally, as WTP mentioned, use == for numeric comparisons (an important note is that you use string1.equals(string2) or compareTo with Strings, just for your future reference).