TriangleOfStars

TriangleOfStars - + "printed: ");...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//Program: Print a triangle of stars / import java.util.*; i public class TriangleOfStars { static Scanner console = new Scanner(System.in); public static void main (String[] args) { int numberOfLines; int counter; int numberOfBlanks; System.out.print("Enter the number of star lines " + "(1 to 20) to be printed: "); //Line 1 numberOfLines = console.nextInt(); //Line 2 System.out.println(); //Line 3 while (numberOfLines < 0 || numberOfLines > 20) //Line 4 { System.out.println("The number of star " + "lines should be between " + "1 and 20"); //Line 5 System.out.print("Enter the number of star " + "lines (1 to 20) to be "
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: + &quot;printed: &quot;); //Line 6 numberOfLines = console.nextInt(); //Line 7 System.out.println (); //Line 8 } numberOfBlanks = 30; //Line 9 for (counter = 1; counter &lt;= numberOfLines; counter++) //Line 10 { printStars(numberOfBlanks, counter); //Line 11 numberOfBlanks--; //Line 12 } } public static void printStars(int blanks, int starsInLine) { int count; for (count = 1; count &lt;= blanks; count++) //Line 13 System.out.print(&quot; &quot;); //Line 14 for (count = 1; count &lt;= starsInLine; count++) //Line 15 System.out.print(&quot; *&quot;); //Line 16 System.out.println(); //Line 17 } }...
View Full Document

This note was uploaded on 06/17/2011 for the course COMP 2301 taught by Professor Staff during the Spring '10 term at Kennesaw.

Ask a homework question - tutors are online