Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SumOfMultiples8July2014 {
  4. public static void main(String args[])
  5. throws java.io.IOException{
  6. System.out.println("You are going to select a range of numbers. " +
  7. "\nThen select another 2 numbers." +
  8. "\nThe program will sum up the multiples of these 2 numbers within the range of numbers you have chosen.");
  9. System.out.println("Press enter to start.");
  10. char choice = (char)System.in.read();
  11. int i,j,k,l,m;
  12. int sum = 0;
  13. Scanner in = new Scanner(System.in);
  14. System.out.println("Please enter the lower limit of the range you want to check.");
  15. j = in.nextInt();
  16. System.out.println("Please enter the upper limit of the range you want to check.");
  17. k = in.nextInt();
  18. System.out.println("Please enter the multiples of a number that you want to be summed.");
  19. l = in.nextInt();
  20. System.out.println("Please enter the multiples of another number that you want to be summed");
  21. m = in.nextInt();
  22. for (i=j; i<=k; i++){
  23. if (i%l==0 || i%m==0){
  24. sum +=i;
  25. }
  26. }
  27. System.out.println("The sum of all multiples of "+l+ " and "+m+" for " +
  28. "\nnatural numbers between " +j+" and " +k+ " inclusive is " +sum);
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement