package eecs1022.finalc; /** * This question is worth 5 marks. Partial marks will be awarded for this question. * * @author Franck van Breugel */ public class Question3 { /** * Print the following pattern of the given length. You may assume that the given length * is greater than or equal to 0. * The pattern is: *+**+***+****+... * * @param length the length of string to be printed. */ public static void pattern(int length) { int count = 1; int i = 0; while (i < length) { for (int j = 0; j < count && i < length; j++) { System.out.print("*"); i++; } if (i < length) { System.out.print("+"); i++; } count++; } System.out.println(); } /** * Tests method. You may add more test cases. * * @param args not applicable. */ public static void main(String[] args) { Question3.pattern(1); Question3.pattern(4); Question3.pattern(9); Question3.pattern(11); Question3.pattern(23); } }