Przeglądaj źródła

(feat) wrap number triangles in newlines

Also add some docstrings and questions
main
Rob Hallam 1 rok temu
rodzic
commit
f3fc7c3984
1 zmienionych plików z 13 dodań i 0 usunięć
  1. +13
    -0
      week1.java

+ 13
- 0
week1.java Wyświetl plik

@@ -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);


Ładowanie…
Anuluj
Zapisz