Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class SumOfMultiples8July2014 {
- public static void main(String args[])
- throws java.io.IOException{
- System.out.println("You are going to select a range of numbers. " +
- "\nThen select another 2 numbers." +
- "\nThe program will sum up the multiples of these 2 numbers within the range of numbers you have chosen.");
- System.out.println("Press enter to start.");
- char choice = (char)System.in.read();
- int i,j,k,l,m;
- int sum = 0;
- Scanner in = new Scanner(System.in);
- System.out.println("Please enter the lower limit of the range you want to check.");
- j = in.nextInt();
- System.out.println("Please enter the upper limit of the range you want to check.");
- k = in.nextInt();
- System.out.println("Please enter the multiples of a number that you want to be summed.");
- l = in.nextInt();
- System.out.println("Please enter the multiples of another number that you want to be summed");
- m = in.nextInt();
- for (i=j; i<=k; i++){
- if (i%l==0 || i%m==0){
- sum +=i;
- }
- }
- System.out.println("The sum of all multiples of "+l+ " and "+m+" for " +
- "\nnatural numbers between " +j+" and " +k+ " inclusive is " +sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement