import java.util.*;
import java.io.*;
import java.text.*;
import java.lang.*;
public class Pascals_Triangle
public static void main(String[] args) throws IntegerEntryFailException
{
new Pascals_Triangle();
}
public Pascals_Triangle()
{
int lines = 0, index = 0;
char q = ';';
String string = null;
Triangle myTriangle = new Triangle();
Scanner scan = new Scanner(System.in);
while(q == ';')
{
q = '?';
System.out.print("How many lines of Pascal's Triangle would you like? ");
string = scan.nextLine();
try
{
lines = Integer.parseInt(string);
if(lines < 1 || lines > 12)
{
throw new IntegerEntryFailException("");
}
}
catch(NumberFormatException exception)
{
System.out.println("\nNumber of lines must be a number. Try again.\n");
q = ';';
}
catch(IntegerEntryFailException exception)
{
System.out.println("\nMust choose a number between 1 and 12.\n");
q = ';';
}
}
index = lines;
System.out.println("\n");
for(int outer = 0; outer < lines; outer++)
{
for(int count = 0; count < index; count++)
System.out.print(" ");
for(int inner = 0; inner < outer; inner++)
{
System.out.print(myTriangle.Triangle(outer, inner) + " ");
}
System.out.println();
index--;
}
System.out.println("\n\n");
}
public class IntegerEntryFailException extends Exception
{
IntegerEntryFailException(String message)
{
super(message);
}
}
public class Triangle
{
int one = 0, two = 0;
public int Triangle(int row, int column)
{
if(row == 0 || column == 0 || row == column+1)
return 1;
one = Triangle(row-1, column);
two = Triangle(row-1,column-1);
return one + two;
}
}
}
here is my code.
code runs, I just get incorret values and am having trouble figuring it out
any help would be much appreciated.