I am working on a Javascript question from a book to build an Isoceles Triangle from methods and a for loop. The question requires that you build two methods first and then use those to create the triangle. I have the below, but it seems to be ignoring these lines:
spaces = spaces – 1;
stars = stars + 2;
because when I run it, I only get 5 lines of 3 spaces and then one asterisk.
Any help is appreciated. Thank you.
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int size;
System.out.print("What size is the triangle? ");
size = input.nextInt();
drawIsoTriangle(size);
}
public static void displaydrawBar(int length) {
for (int i = 0; i < length; i++) {
System.out.print("*");
}
}
public static void displaydrawBar(int length, String mark) {
for (int i = 0; i < length; i++) {
System.out.print(mark);
}
}
public static void drawIsoTriangle(int size) {
for (int i = 0; i < size; i++) {
int spaces = size - 1;
int stars = 1;
displaydrawBar(spaces, " ");
displaydrawBar(stars);
System.out.println();
spaces = spaces - 1;
stars = stars + 2;
}
}
}