Write a program to find numbers that are multiples of three and five between 0 to 1000
Updated: Aug. 15, 2022 — Training Time: 1 Minute
Overseen by: Archangel Macsika
All Training Resources
Scroll for more menu list
Topic: Generic - Java Programming
Difficulty: Easy.
Companies who previously asked this: -.
Objective: Write a program to find numbers that are multiples of three and five between 0 to 1000.
Input: None.
Expected Output: Numbers that are multiples of three and five.
Sikademy Solution
package sikademy;
/**
*
* @author Archangel Macsika
*/
import java.util.logging.Logger;
public class MulitpleOfThreeAndFive {
private static final Logger LOG=Logger.getLogger(MulitpleOfThreeAndFive.class.getName());
public static void main(String[] args){
LOG.info("Running main method");
int divisibleByFive=0;
int divisibleByThree=0;
for(int i=0;i<1000;i++){
if(i%3==0){
divisibleByThree+=i;
}
else if(i%5 == 0){
divisibleByFive += i;
}
}
LOG.info("The sum is : " + (divisibleByFive + divisibleByThree));
}
}