I am trying to solve the following problem:
Problem:
Write a program that displays the integers between 1 and 100 that are divisible by either 6 or 7 but not both.
Here is my code:
import acm.program.*;
public class Problem4 extends ConsoleProgram
{
public void run()
{
for (int i = 1; i <= 100; i++)
{
boolean num = ((i % 6 == 0) || (i % 7 == 0));
if (num == true)
println(i + " is divisible");
}
}
}
The above code shows the following answers: 6,7,12,14,18,21,24,28,30,35,36,42,48,49,54,56,60,63,66,70,72,77,78,84,90,91,96,98
Now the bold number " 42 and 84 " are both divisbile by 6 and 7. Now If i change the || to && in the above code, the result shows only 42 and 84.
What change should i do to remove these 2 numbers from the final result.
it seems to me as the answer is right in front of me but i am not able to get a hold of it.
Can someone help please ?