Computer Science, asked by Monkiko, 2 months ago

W.A.P to display a number which are not divisible by 3 and 7 between 1 to 100 in JAVA​

Answers

Answered by allysia
3

Answer:

If you mean display number not divisibly by both 3 and 7 (as in 21, 42 and so one)

The program:

\\\tt public\ class\ oh\ \{	public\ static\ void\ main(String[] args) \{		for\ (int\ i = 1; i <101; i++) \{			if (i \%3!=0 || i \%7!=0) \{									System.out.print(i+" " );			\}	\}\}

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:

\\\tt public\ class\ oh\ \{	public\ static\ void\ main(String[] args) \{		for\ (int\ i = 1; i <  101; i++) \{			if (i \%3!=0 \&\& i \%7!=0) \{									System.out.print(i+" " );			\}	\}\}

Explanation:

  1. 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()
  2. similarly i%7!=0 || i%3!=0 will check if the number is either 7 or 3.

Attachments:
Answered by BrainlyProgrammer
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:-

  1. The program runs a loop from 1 to 100
  2. In each iteration, it checks if the loop value is divisible by 3 and 7 or not.
  3. If not divisible, it displays the number
  4. Else it will continue with next iteration

__________________________

•Output Attached.

Attachments:
Similar questions