int n = 15; int sum = 0; // ... your code here ... System.out.println (sum); // Should print 45.The result seen on the screen should be 45. Hint: look at Module 6 and how we printed odd numbers. Then, modify that code to sum up odd numbers. Now, can you change this to sum up multiples of 3?
(a(a+1)(a+2) ... (b-1)b) - (a + (a+1) + .... + (b-1) + b).In other words, what is the product of all numbers between a and b (including a and b)? And what is the sum of these numbers? The desired output is the product minus the sum. For example, if a=3 and b=7, the product-sum difference becomes
(3 * 4 * 5 * 6 * 7) - (3 + 4 + 5 + 6 + 7) = 2520 - 25 = 2495.Thus, your program should print out 2495.
Your program should define variables
a
and
b
so that their values can be changed when we test your programs.
Thus, your code inside
main
will start like this:
int a = 10;
int b = 15;
// ... your loops etc here ...
// Then print the desired output.
You ought to test your program by trying out different
values of a and b.
Recommended, but not required: