I'm working on some homework for my Intro to Programming class and one of the questions is
Write a program that displays all the integers from 1 to 1000 that are not evenly divisible by 13. (Hint: x is not evenly divisible by 13 if the expression x % 13 ! = 0 is true. Recall that % is the remainder operator.) My train of thought was that what I want the program to do is to take x, whatever it may be, if it's less than 1000, then divide it by 13 and if the remainder is not 0 then display the number. If the remainder is 0, don't display the number.
My first attempt was the following,
public class Ch4_Lab_5
{
public static void main(String[] args)
{
int x = 1;
while (x < 1000)
{
System.out.println(x);
x++;
}
}
}
but when it runs it simply prints the numbers 1 through 999. I'm thinking maybe this needs to be an if/else statement but I'm unsure as to what the "else" parameters would be.
My book gives this as an example:
public class Ch4_Example
{
public static void main(String[] args)
{
int x = 1;
while (x*x < 5000)
{
System.out.println(x + " squared = " + x*x);
x++;
}
}
}
And of course it worked perfectly.
The program I'm supposed to be writing isn't quite the same as the example given in the book but it's the same principle, and I've been playing around with this for a while and can't seem to identify the issue.
I'm sure this is a really simple question with an even simpler answer but I'm brand-spanking new to programming and I'm a bit lost.
Any ideas?