package eecs1022.finalb; /** * This question is worth 5 marks. Partial marks will be awarded for this question. * * @author Franck van Breugel */ public class Question2 { /** * Returns the value of 1 * 2 * ... * n. You have to use a loop to solve this question. * You may assume that n is greater than 0. * * @param n a positive integer. * @return the value of 1 * 2 * ... * n */ public static int product(int n) { int product = 1; for (int i = 1; i <= n; i++) { product = product * i; } return product; } /** * Tests method. You may add more test cases. * * @param args not applicable. */ public static void main(String[] args) { System.out.println(Question2.product(1)); System.out.println(Question2.product(2)); System.out.println(Question2.product(3)); System.out.println(Question2.product(4)); System.out.println(Question2.product(5)); } }