Преглед на файлове

(feat) wrap number triangles in newlines

Also add some docstrings and questions
main
Rob Hallam преди 1 година
родител
ревизия
f3fc7c3984
променени са 1 файла, в които са добавени 13 реда и са изтрити 0 реда
  1. +13
    -0
      week1.java

+ 13
- 0
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);


Зареждане…
Отказ
Запис