Exercise
Multiples
Objetive
Write a java program to display on the screen the numbers from 1 to 500 that are multiples of both 3 and 5. (Hint: Use the modulo operator to check for divisibility by both 3 and 5.)
Example Code
public class Program {
// Main entry point of the program
public static void main(String[] args) {
// Loop through numbers from 1 to 500
for (int i = 1; i <= 500; i++) {
// Check if the number is divisible by both 3 and 5 using the modulo operator
if (i % 3 == 0 && i % 5 == 0) {
// If divisible by both, display the number
System.out.println(i);
}
}
}
}