W.A.P to display a number which are not divisible by 3 and 7 between 1 to 100 in JAVA
Answers
Answered by
3
Answer:
If you mean display number not divisibly by both 3 and 7 (as in 21, 42 and so one)
The program:
If you mean display number not divisibly by neither 3 or 7 (as in 3,6,7,9,12,14 and so one)
The program:
Explanation:
- i%7!=0 && i%3!=0 will check if the number if the number is divisible by 7 and 3 or not and the print the number with System.out.print()
- similarly i%7!=0 || i%3!=0 will check if the number is either 7 or 3.
Attachments:
![](https://hi-static.z-dn.net/files/d20/29a2ddbf481b6021867a146c24723380.jpg)
![](https://hi-static.z-dn.net/files/d20/77f277b2d79140a5f5cfb16a2e91374c.jpg)
Answered by
3
Question:-
- To Display those numbers which are not divisible by 3 and 7 between 1 to 100
Code Language:-
- Java
_______________________
Code:-
package Coder;
public class DivCheck
{
public static void main (String ar [])
{
System.out.println("The numbers not divisible by 3 and 7 are:");
for(i=1;i<=100;i++)
{
if(i%3!=0)&&(i%7!=0)
System.out.println(i);
}
}
}
__________________________
Code Explaination:-
- The program runs a loop from 1 to 100
- In each iteration, it checks if the loop value is divisible by 3 and 7 or not.
- If not divisible, it displays the number
- Else it will continue with next iteration
__________________________
•Output Attached.
Attachments:
![](https://hi-static.z-dn.net/files/d58/53a5528d612f1880a2a6f8ae5871ab21.jpg)
![](https://hi-static.z-dn.net/files/d2b/dba29223a2147b7466983b6fe3a1134f.jpg)
Similar questions
Math,
3 months ago
Computer Science,
3 months ago
Science,
3 months ago
Hindi,
6 months ago
Math,
6 months ago
Social Sciences,
1 year ago