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:
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:
Similar questions