Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

How can you defend against SQL injection attacks?

Answered: 1 week ago

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago