//************************************************************************* // // NumberTriangle accepts an integer number as input from the user, and then // generates a triangle of numbers as output. The triangle comprises rows of // sequential numbers up to and including the number entered by the user. // Kelli Wiseth // 9-July-2004 // Platform: Wintel [Windows 2000] // JDK version: JDK 1.4.1 // //************************************************************************* import java.io.*; class NumberTriangle { public static void main (String args[]) throws IOException { BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); String num1; int rows=0; int columns=0; int total_rows=0; do { System.out.print("Please enter the size of the triangle: "); System.out.flush(); num1=stdin.readLine(); total_rows=Integer.parseInt(num1); if (total_rows <= 0) System.out.println("Sorry. I can't create an empty triangle. " + " \nPlease enter a whole number greater than 0. "); } while (total_rows <= 0); for (rows = 1; rows <= total_rows; rows++) { for (columns=1; columns <= rows; columns++) System.out.print (rows); System.out.println(); } }//main method }//NumberTriangle class