In: Computer Science
Write a complete static method named addUp that accepts, in order, an integer number and an integer thisMany as parameters and that prints a complete line of output reporting all the numbers that result from adding number to itself thisMany number of times (starting at 1 and ending at thisMany). For example, the following calls:
addUp(3, 5);
addUp(7, 3);
should produce this output:
Adding up 3 for 5 times gives: 3, 6, 9, 12, 15
Adding up 7 for 3 times gives: 7, 14, 21
Notice that the answers are separated by commas and a space. You must exactly reproduce this format. You may assume that the number of add ups you will be asked to do (thisMany) is greater than or equal to 1. Your method must work with any value of number including negative numbers and zero.
Write a main method that tests your addUp method.
public class temp { public static void main(String[] args) { addUp(3, 5); System.out.println(); addUp(7, 3); } // method to display the sum of numbers this many times public static void addUp(int number, int thisMany) { System.out.print("Adding up " + number + " for " + thisMany + " times gives: "); int sum = number; // loop to sum and print the value for (int i = 0; i < thisMany; i++) { System.out.print(sum); // display comma and space if (i != thisMany-1) { System.out.print(", "); } // calculate sum sum = sum + number; } }
}
FOR HELP PLEASE COMMENT.
THANK YOU