<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">import CS99.*;

/**
 * Triangles - Lab 5
 * Author: Michael Clarkson
 * NetID: mrc26
 * Date: 7/10/00
 */
class Triangles {

	public static void main(String[] args) {
		int size;		// width and height of triangle patterns
		int spaces;		// number of spaces in a row of a pattern
		int i, j;		// index variables for pattern loops
		
		// Loop to get and validate input
		boolean valid = false;
		do {
			System.out.print("Enter the size: ");
			size = Console.readInt();
			
			if (size &lt; 2) {
				System.out.println("Size must be &gt;= 2.");
			} else {
				valid = true;
			}
		} while (!valid);
			
		// Pattern A:
		// *
		// **
		// ***
		for (i = 1; i &lt;= size; i++) {
			for (j = 1; j &lt;= i; j++) {
				System.out.print("*");
			}
			System.out.println();
		}

		System.out.println();
		
		// Pattern B:
		// ***
		// **
		// *
		for (i = size; i &gt;= 1; i--) {
			for (j = 1; j &lt;= i; j++) {
				System.out.print("*");
			}
			System.out.println();
		}

		System.out.println();
		
		// Pattern C:
		// ***
		//  **
		//   *
		for (i = size; i &gt;= 1; i--) {
			spaces = size - i;
			for (j = 1; j &lt;= spaces; j++) {
				System.out.print(" ");
			}
			for (j = 1; j &lt;= i; j++) {
				System.out.print("*");
			}
			System.out.println();
		}

		System.out.println();
		
		// Pattern D:
		//   *
		//  **
		// ***
		for (i = 1; i &lt;= size; i++) {
			spaces = size - i;
			for (j = 1; j &lt;= spaces; j++) {
				System.out.print(" ");
			}
			for (j = 1; j &lt;= i; j++) {
				System.out.print("*");
			}
			System.out.println();
		}

		
	}

}</pre></body></html>