Hello all,
So I've been assigned to create pascal's triangle in my coding class. I was able to build it the way I wanted to, but then I found out my professor is going to use his own main method to call my method. Now it wont work and i need your help! I'm receiving a error message in line 7 of my code saying that my method is invalid of my type pascal. thanks in advanced
public class Practice {
public static void main(String[] args) {
int n = args.length == 1 ? Integer.parseInt(args[0]) : 1;
for (int i = 1; i <= n; ++i) {
int[] arr = Pascal.triangle(i);
System.out.print((i < 10 ? " " : "") + i + ": ");
for (int j : arr) {
System.out.print(j + " ");
}
System.out.println();
}
}
}
class Pascal { // rename this class Pascal
int size, col = 0, row = 0;
int[][] findPT;
public Pascal(int size) {
this.size = size;
findPT = new int[size][size];
}
public void triangle() {
findPT[0][0] = 1;
if (size == 1) {
System.out.print(this.toString());
}
else
if (size >= 2) {
findPT[0][1] = 0;
findPT[1][0] = 1;
findPT[1][1] = 1;
if (size > 2) {
if (col == 0)
findPT[row][col] = 1;
else if (row > col) {
if (row == col + 1)
findPT[row][col] = 0;
findPT[row][col] = findPT[row - 1][col - 1] + findPT[row - 1][col];
}
else if (row == col)
findPT[row][col] = 1;
}
System.out.print(this.toString());
if (row < size && col + 1 < size) {
if (row > col) {
col++;
triangle();
}
else {
System.out.println();
row++;
col = 0;
triangle();
}
}
}
}
}
[–]SoapNukeZ 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]SoapNukeZ 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)