In: Computer Science
Java
Write a program that displays all the numbers from 100 to 200 that are divisible by 5 or 6, but not both
Make sure all instructions and outputs for the user are explicit
Java code:
public class Main{
public static void main(String[] args){
//printing a message to user about what this program does
System.out.println("All numbers between 100 and 200 that are
divisible by 5 or 6, but not both are:");
//looping from 100 to 200
for(int i=100;i<=200;i++){
//checking if the number is divisible by 5 or 6 and not both
if((i%5==0 || i%6==0) && !(i%5==0 && i%6==0))
//printing the number
System.out.println(i);
}
}
}
Screenshot:
Output: