132k views
3 votes
Create a loop that will output all the numbers less than 200 that are evenly divisible (meaning remainder is zero) by both 5 and 7. 35, 70, 105, 140, 175

User Dsmtoday
by
6.6k points

1 Answer

6 votes

Answer:

public class num7 {

public static void main(String[] args) {

int n =1;

while(n<200){

if(n%5==0 && n%7==0){

System.out.print(n);

System.out.print(",");

}

n++;

}

}

}

Step-by-step explanation:

  • In Java programming Language
  • Create and initialize an int variable (n=1)
  • Create a while loop with the condition while (n<200)
  • Within the while loop use the modulo operator % to check for divisibility by 5 and 7
  • Print the numbers divisible by 5 and 7
User Uliysess
by
5.3k points