Question: I need to be able to keep trying numbers if the input is not an int or not a number between 1-13. public class PascalsTriangle

I need to be able to keep trying numbers if the input is not an int or not a number between 1-13.

public class PascalsTriangle

{

int[][] array;

public PascalsTriangle(int number)

{

createTriangle(number);

}

private void createTriangle(int r)

{

array = new int[r][];

for (int i = 0 ; i < r ; i++)

{

array[i] = new int [6] ;

}

for (int[] array1 : array) {

for (int col = 0; col < array1.length; col++) {

array1[col] = 1;

}

}

}

public String toString()

{

StringBuffer grid= new StringBuffer();

for(int index=0; index

for(int index2=0; index2

grid.append(array[index][index2]).append(" ");

}

grid.append(" ");

}

return grid.toString();

}

}

=======

import java.util.Scanner;

/** * * @author javie */ public class Test { public static void main(String[] args) { int numberOfRows = 0; Scanner input = new Scanner(System.in); System.out.println("Provide number between 1 - 13 for the " + " rows of the Pascals' Triangle"); PascalsTriangle newTriangle; while (input.hasNextInt()) { do{

numberOfRows = input.nextInt();

if (numberOfRows < 1 || numberOfRows > 13 )

System.out.println("The number you entered is not between 1 - 13");

else

System.out.println(newTriangle = new PascalsTriangle(numberOfRows));

}while(input.hasNextInt());

} System.out.print(" This is not a valid interger, please try again");

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!