|
@@ -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, preceding number of spaces starts at n=rows and decrements |
|
|
- for even-sized triangles even numbers have odd spaces and vice versa |
|
|
- for even-sized triangles even numbers have odd spaces and vice versa |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
System.out.println(String.format("")); |
|
|
int spaces = num; |
|
|
int spaces = num; |
|
|
for (int i = 1; i <= num; i++) { |
|
|
for (int i = 1; i <= num; i++) { |
|
|
System.out.println(" ".repeat(spaces) |
|
|
System.out.println(" ".repeat(spaces) |
|
@@ -319,14 +320,26 @@ class Lab6 extends Lab { |
|
|
); |
|
|
); |
|
|
spaces--; |
|
|
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) { |
|
|
public void writeTimesTable(int num, int limit) { |
|
|
for (int i = 0; i < (limit + 1); i++) { |
|
|
for (int i = 0; i < (limit + 1); i++) { |
|
|
System.out.printf("%d\t", num * 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) { |
|
|
public void writeTimesTable(int num) { |
|
|
int DEFAULT_LIMIT = 10; |
|
|
int DEFAULT_LIMIT = 10; |
|
|
writeTimesTable(num, DEFAULT_LIMIT); |
|
|
writeTimesTable(num, DEFAULT_LIMIT); |
|
|