java - Finding integers that are divisible by 6 or 7 but not both -
itemprop = "text">
I am trying to write a program that represents the integer between 1 and 100, which is 6 or 7 divided by but not both .
Here's my code:
Import acm.program *; Public class problem 4 console program {Public running zero () (for (ii = 1; i & lt; = 100; i ++) {boolean number = ((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 9 6,98
Now the bold 42 and 84 are both divisbile by 6 and 7. Now if I type in the above code ||
I change from & amp; amp;
, results are only 42 and 84.
What should I do to delete these 2 numbers from the results?
You have to show your status :
Boolean number = (i% 6 == 0 || i% 7 == 0) & amp;! (I% 6 == & amp; amp; i% 7 == 0);
It is basically not converting " but both " into Java code):
Comments
Post a Comment