From f3fc7c3984a2b00e30c5b870941362747fbb978c Mon Sep 17 00:00:00 2001 From: Rob Hallam <0504004h@student.gla.ac.uk> Date: Tue, 19 Sep 2023 20:41:38 +0100 Subject: [PATCH] (feat) wrap number triangles in newlines Also add some docstrings and questions --- week1.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/week1.java b/week1.java index 7544330..d8b1bc4 100644 --- a/week1.java +++ b/week1.java @@ -311,6 +311,7 @@ class Lab6 extends Lab { - for even-sized triangles, preceding number of spaces starts at n=rows and decrements - for even-sized triangles even numbers have odd spaces and vice versa */ + System.out.println(String.format("")); int spaces = num; for (int i = 1; i <= num; i++) { System.out.println(" ".repeat(spaces) @@ -319,14 +320,26 @@ class Lab6 extends Lab { ); spaces--; } + System.out.println(String.format("")); } + /** + * @param num The number to write the times table for + * @param limit How many multiples to show + */ public void writeTimesTable(int num, int limit) { for (int i = 0; i < (limit + 1); i++) { System.out.printf("%d\t", num * i); } } + /* TOASK - overload example. + Question: is there a better way of doing optional function parameters in java? + */ + /** + * Write times table for num (10 entries) + * @param num Number to show times table for + */ public void writeTimesTable(int num) { int DEFAULT_LIMIT = 10; writeTimesTable(num, DEFAULT_LIMIT);