//The following code snippet illustrates how to use a MediaTracker to wait while an image is prepared:
//file: StatusImage.java
import java.awt.*;
import javax.swing.*;
public class StatusImage extends JComponent
{
boolean loaded = false;
String message = "Loading...";
Image image;
public StatusImage( Image image ) { this.image = image; }
public void paint(Graphics g) {
if (loaded)
g.drawImage(image, 0, 0, this);
else {
g.drawRect(0, 0, getSize().width - 1, getSize().height - 1);
g.drawString(message, 20, 20);
}
}
public void loaded() {
loaded = true;
repaint();
}
public void setMessage( String msg ) {
message = msg;
repaint();
}
public static void main( String [] args ) {
JFrame frame = new JFrame("TrackImage");
Image image = Toolkit.getDefaultToolkit().getImage( args[0] );
StatusImage statusImage = new StatusImage( image );
frame.add( statusImage );
frame.setSize(300,300);
frame.setVisible(true);
MediaTracker tracker = new MediaTracker( statusImage );
int MAIN_IMAGE = 0;
tracker.addImage( image, MAIN_IMAGE );
try {
tracker.waitForID( MAIN_IMAGE ); }
catch (InterruptedException e) {}
if ( tracker.isErrorID( MAIN_IMAGE ) )
statusImage.setMessage( "Error" );
else
statusImage.loaded();
}
}
ImageObserver Interface - Loading Image - Java Sample Program
//file: ObserveImageLoad.java
import java.awt.*;
import java.awt.image.*;
public class ObserveImageLoad {
public static void main( String [] args)
{
ImageObserver myObserver = new ImageObserver() {
public boolean imageUpdate( Image image, int flags, int x, int y, int width, int height)
{
if ( (flags & HEIGHT) !=0 )
System.out.println("Image height = " + height );
if ( (flags & WIDTH ) !=0 )
System.out.println("Image width = " + width );
if ( (flags & FRAMEBITS) != 0 )
System.out.println("Another frame finished.");
if ( (flags & SOMEBITS) != 0 )
System.out.println("Image section :" + new Rectangle( x, y, width, height ) );
if ( (flags & ALLBITS) != 0 )
System.out.println("Image finished!");
if ( (flags & ABORT) != 0 )
System.out.println("Image load aborted...");
return true;
}
};
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image img = toolkit.getImage( args[0] );
toolkit.prepareImage( img, -1, -1, myObserver );
}
}
import java.awt.*;
import java.awt.image.*;
public class ObserveImageLoad {
public static void main( String [] args)
{
ImageObserver myObserver = new ImageObserver() {
public boolean imageUpdate( Image image, int flags, int x, int y, int width, int height)
{
if ( (flags & HEIGHT) !=0 )
System.out.println("Image height = " + height );
if ( (flags & WIDTH ) !=0 )
System.out.println("Image width = " + width );
if ( (flags & FRAMEBITS) != 0 )
System.out.println("Another frame finished.");
if ( (flags & SOMEBITS) != 0 )
System.out.println("Image section :" + new Rectangle( x, y, width, height ) );
if ( (flags & ALLBITS) != 0 )
System.out.println("Image finished!");
if ( (flags & ABORT) != 0 )
System.out.println("Image load aborted...");
return true;
}
};
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image img = toolkit.getImage( args[0] );
toolkit.prepareImage( img, -1, -1, myObserver );
}
}
Circle (User Define Classes) - Java Sample Program
public class Circle
{
private double radius;
//Default constructor
//Sets the radius to 0
Circle()
{
radius = 0;
}
//Constructor with a parameter
//Sets the radius to the value specified by the parameter r.
Circle(double r)
{
radius = r;
}
//Method to set the radius of the circle.
//Sets the radius to the value specified by the parameter r.
public void setRadius(double r)
{
radius = r;
}
//Method to return the radius of the circle.
//Returns the radius of the circle.
public double getRadius()
{
return radius;
}
//Method to compute and return the area of the circle.
//Computes and returns the area of the circle.
public double area()
{
return Math.PI * Math.PI * radius;
}
//Method to compute and return the perimeter of the circle.
//Computes and returns the area of the circle.
public double perimeter()
{
return 2 * Math.PI * radius;
}
//Method to return the radius, area, perimeter of the circle
//as a string.
public String toString()
{
return String.format("Radius = %.2f, Perimeter = %.2f"+ ", Area = %.2f%n", radius, perimeter(), area());
}
}
We leave the UML class diagram of the class Circle as an exercise for you.
The following program shows how to use the class Circle in a program.
// Program to test various operations of the class Circle.
import java.util.*; //Line 1
public class TestProgCircle //Line 2
{ //Line 3
static Scanner console = new Scanner(System.in); //Line 4
public static void main(String[] args) //Line 5
{ //Line 6
Circle firstCircle = new Circle(); //Line 7
Circle secondCircle = new Circle(12); //Line 8
double radius; //Line 9
System.out.println("Line 10: firstCircle: " + firstCircle); //Line 10
System.out.println("Line 11: secondCircle: " + secondCircle); //Line 11
System.out.print("Line 12: Enter the radius: "); //Line 12
radius = console.nextDouble(); //Line 13
System.out.println(); //Line 14
firstCircle.setRadius(radius); //Line 15
System.out.println("Line 16: firstCircle: " + firstCircle ); //Line 16
if (firstCircle.getRadius() > secondCircle.getRadius()) //Line 17
System.out.println("Line 18: The radius of "+ "the first circle is greater than "+ "the radius of the second circle. "); //Line 18
else if (firstCircle.getRadius()< secondCircle.getRadius()) //Line 19
System.out.println("Line 20: The radius of "+ "the first circle is less than the " + "radius of the second circle. "); //Line 20
else //Line 21
System.out.println("Line 22: The radius of " + "both the circles are the same."); //Line 22
}//end main //Line 23
} //Line 24
Sample Sample Output:
Line 10: firstCircle: Radius = 0.00, Perimeter = 0.00, Area = 0.00
Line 11: secondCircle: Radius = 12.00, Perimeter = 75.40, Area = 118.44
Line 12: Enter the radius: 10
Line 16: firstCircle: Radius = 10.00, Perimeter = 62.83, Area = 98.70
Line 20: The radius of the first circle is less than the radius of the second circle.
The preceding program works as follows. The statement in Line 7 creates the object
firstCircle and using the default constructor sets the radius to 0. The statement in
Line 8 creates the object secondCircle and sets the radius to 12. The statement in Line
9 declares the double variable radius. The statement in Line 10 outputs the radius, area,
and perimeter of the firstCircle. Similarly, the statement in Line 11 outputs the
radius, area, and perimeter of the secondCircle The statement in Line 12 prompts the
user to enter the value of radius. The statement in Line 13 stores the value entered by
the user in the variable radius. The statement in Line 15 uses the value of radius to set
the radius of firstCircle. The statement in Line 16 outputs the radius, area, and
perimeter of the firstCircle. The statements in Lines 17 to 23 compare the radius of
firstCircle and secondCircle and output the appropriate result.
{
private double radius;
//Default constructor
//Sets the radius to 0
Circle()
{
radius = 0;
}
//Constructor with a parameter
//Sets the radius to the value specified by the parameter r.
Circle(double r)
{
radius = r;
}
//Method to set the radius of the circle.
//Sets the radius to the value specified by the parameter r.
public void setRadius(double r)
{
radius = r;
}
//Method to return the radius of the circle.
//Returns the radius of the circle.
public double getRadius()
{
return radius;
}
//Method to compute and return the area of the circle.
//Computes and returns the area of the circle.
public double area()
{
return Math.PI * Math.PI * radius;
}
//Method to compute and return the perimeter of the circle.
//Computes and returns the area of the circle.
public double perimeter()
{
return 2 * Math.PI * radius;
}
//Method to return the radius, area, perimeter of the circle
//as a string.
public String toString()
{
return String.format("Radius = %.2f, Perimeter = %.2f"+ ", Area = %.2f%n", radius, perimeter(), area());
}
}
We leave the UML class diagram of the class Circle as an exercise for you.
The following program shows how to use the class Circle in a program.
// Program to test various operations of the class Circle.
import java.util.*; //Line 1
public class TestProgCircle //Line 2
{ //Line 3
static Scanner console = new Scanner(System.in); //Line 4
public static void main(String[] args) //Line 5
{ //Line 6
Circle firstCircle = new Circle(); //Line 7
Circle secondCircle = new Circle(12); //Line 8
double radius; //Line 9
System.out.println("Line 10: firstCircle: " + firstCircle); //Line 10
System.out.println("Line 11: secondCircle: " + secondCircle); //Line 11
System.out.print("Line 12: Enter the radius: "); //Line 12
radius = console.nextDouble(); //Line 13
System.out.println(); //Line 14
firstCircle.setRadius(radius); //Line 15
System.out.println("Line 16: firstCircle: " + firstCircle ); //Line 16
if (firstCircle.getRadius() > secondCircle.getRadius()) //Line 17
System.out.println("Line 18: The radius of "+ "the first circle is greater than "+ "the radius of the second circle. "); //Line 18
else if (firstCircle.getRadius()< secondCircle.getRadius()) //Line 19
System.out.println("Line 20: The radius of "+ "the first circle is less than the " + "radius of the second circle. "); //Line 20
else //Line 21
System.out.println("Line 22: The radius of " + "both the circles are the same."); //Line 22
}//end main //Line 23
} //Line 24
Sample Sample Output:
Line 10: firstCircle: Radius = 0.00, Perimeter = 0.00, Area = 0.00
Line 11: secondCircle: Radius = 12.00, Perimeter = 75.40, Area = 118.44
Line 12: Enter the radius: 10
Line 16: firstCircle: Radius = 10.00, Perimeter = 62.83, Area = 98.70
Line 20: The radius of the first circle is less than the radius of the second circle.
The preceding program works as follows. The statement in Line 7 creates the object
firstCircle and using the default constructor sets the radius to 0. The statement in
Line 8 creates the object secondCircle and sets the radius to 12. The statement in Line
9 declares the double variable radius. The statement in Line 10 outputs the radius, area,
and perimeter of the firstCircle. Similarly, the statement in Line 11 outputs the
radius, area, and perimeter of the secondCircle The statement in Line 12 prompts the
user to enter the value of radius. The statement in Line 13 stores the value entered by
the user in the variable radius. The statement in Line 15 uses the value of radius to set
the radius of firstCircle. The statement in Line 16 outputs the radius, area, and
perimeter of the firstCircle. The statements in Lines 17 to 23 compare the radius of
firstCircle and secondCircle and output the appropriate result.
Clock (User Define Classes) - Java Sample Program
//The definition of the class Clock is:
public class Clock
{
private int hr; //store hours
private int min; //store minutes
private int sec; //store seconds
//Default constructor
//Postcondition: hr = 0; min = 0; sec = 0
public Clock()
{
setTime(0, 0, 0);
}
//Constructor with parameters, to set the time
//The time is set according to the parameters.
//Postcondition: hr = hours; min = minutes;
// sec = seconds
public Clock(int hours, int minutes, int seconds)
{
setTime(hours, minutes, seconds);
}
//Method to set the time
//The time is set according to the parameters.
//Postcondition: hr = hours; min = minutes;
// sec = seconds
public void setTime(int hours, int minutes, int seconds)
{
if (0 <= hours && hours < 24)
hr = hours;
else
hr = 0;
if (0 <= minutes && minutes < 60)
min = minutes;
else
min = 0;
if (0 <= seconds && seconds < 60)
sec = seconds;
else
sec = 0;
}
//Method to return the hours
//Postcondition: the value of hr is returned
public int getHours()
{
return hr;
}
//Method to return the minutes
//Postcondition: the value of min is returned
public int getMinutes()
{
return min;
}
//Method to return the seconds
//Postcondition: the value of sec is returned
public int getSeconds()
{
return sec;
}
//Method to print the time
//Postcondition: Time is printed in the form hh:mm:ss
public void printTime()
{
if (hr < 10)
System.out.print("0");
System.out.print(hr + ":");
if (min < 10)
System.out.print("0");
System.out.print(min + ":");
if (sec < 10)
System.out.print("0");
System.out.print(sec);
}
//Method to increment the time by one second
//Postcondition: The time is incremented by one second
//If the before-increment time is 23:59:59, the time
//is reset to 00:00:00
public void incrementSeconds()
{
sec++;
if (sec > 59)
{
sec = 0;
incrementMinutes(); //increment minutes
}
}
//Method to increment the time by one minute
//Postcondition: The time is incremented by one minute
//If the before-increment time is 23:59:53, the time
//is reset to 00:00:53
public void incrementMinutes()
{
min++;
if (min > 59)
{
min = 0;
incrementHours(); //increment hours
}
}
//Method to increment the time by one hour
//Postcondition: The time is incremented by one hour
//If the before-increment time is 23:45:53, the time
//is reset to 00:45:53
public void incrementHours()
{
hr++;
if (hr > 23)
hr = 0;
}
//Method to compare two times
//Postcondition: Returns true if this time is equal to
// otherClock; otherwise returns false
public boolean equals(Clock otherClock)
{
return (hr == otherClock.hr
&& min == otherClock.min
&& sec == otherClock.sec);
}
//Method to copy time
//Postcondition: The instance variables of otherClock
// copied into the corresponding data
// are members of this time.
// hr = otherClock.hr;
// min = otherClock.min;
// sec = otherClock.sec;
public void makeCopy(Clock otherClock)
{
hr = otherClock.hr;
min = otherClock.min;
sec = otherClock.sec;
}
//Method to return a copy of time
//Postcondition: A copy of the object is created and
// a reference of the copy is returned
public Clock getCopy()
{
Clock temp = new Clock();
temp.hr = hr;
temp.min = min;
temp.sec = sec;
return temp;
}
}
//Program to test various operations of the class Clock
import java.util.*;
public class TestProgClock
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{
Clock myClock = new Clock(5, 4, 30); //Line 1
Clock yourClock = new Clock(); //Line 2
int hours; //Line 3
int minutes; //Line 4
int seconds; //Line 5
System.out.print("Line 6: myClock: "); //Line 6
myClock.printTime(); //Line 7
System.out.println(); //Line 8
System.out.print("Line 9: yourClock: "); //Line 9
yourClock.printTime(); //Line 10
System.out.println(); //Line 11
yourClock.setTime(5, 45, 16); //Line 12
System.out.print("Line 13: After setting "+ "the time - yourClock: "); //Line 13
yourClock.printTime(); //Line 14
System.out.println(); //Line 15
if (myClock.equals(yourClock)) //Line 16
System.out.println("Line 17: Both the " + "times are equal."); //Line 17
else //Line 18
System.out.println("Line 19: The two " + "times are not " + "equal."); //Line 19
System.out.print("Line 20: Enter hours, "+ "minutes, and seconds: "); //Line 20
hours = console.nextInt(); //Line 21
minutes = console.nextInt(); //Line 22
seconds = console.nextInt(); //Line 23
System.out.println(); //Line 24
myClock.setTime(hours, minutes, seconds); //Line 25
System.out.print("Line 26: New time of "+ "myClock: "); //Line 26
myClock.printTime(); //Line 27
System.out.println(); //Line 28
myClock.incrementSeconds(); //Line 29
System.out.print("Line 30: After "+ "incrementing the time by " + "one second, myClock: "); //Line 30
myClock.printTime(); //Line 31
System.out.println(); //Line 32
yourClock.makeCopy(myClock); //Line 33
System.out.print("Line 34: After copying "+ "myClock into yourClock, " + "yourClock: "); //Line 34
yourClock.printTime(); //Line 35
System.out.println(); //Line 36
}//end main
}
Sample Output:
Line 6: myClock: 05:04:30
Line 9: yourClock: 00:00:00
Line 13: After setting the time - yourClock: 05:45:16
Line 19: The two times are not equal.
Line 20: Enter hours, minutes, and seconds: 11 22 59
Line 26: New time of myClock: 11:22:59
Line 30: After incrementing the time by one second, myClock: 11:23:00
Line 34: After copying myClock into yourClock, yourClock: 11:23:00
public class Clock
{
private int hr; //store hours
private int min; //store minutes
private int sec; //store seconds
//Default constructor
//Postcondition: hr = 0; min = 0; sec = 0
public Clock()
{
setTime(0, 0, 0);
}
//Constructor with parameters, to set the time
//The time is set according to the parameters.
//Postcondition: hr = hours; min = minutes;
// sec = seconds
public Clock(int hours, int minutes, int seconds)
{
setTime(hours, minutes, seconds);
}
//Method to set the time
//The time is set according to the parameters.
//Postcondition: hr = hours; min = minutes;
// sec = seconds
public void setTime(int hours, int minutes, int seconds)
{
if (0 <= hours && hours < 24)
hr = hours;
else
hr = 0;
if (0 <= minutes && minutes < 60)
min = minutes;
else
min = 0;
if (0 <= seconds && seconds < 60)
sec = seconds;
else
sec = 0;
}
//Method to return the hours
//Postcondition: the value of hr is returned
public int getHours()
{
return hr;
}
//Method to return the minutes
//Postcondition: the value of min is returned
public int getMinutes()
{
return min;
}
//Method to return the seconds
//Postcondition: the value of sec is returned
public int getSeconds()
{
return sec;
}
//Method to print the time
//Postcondition: Time is printed in the form hh:mm:ss
public void printTime()
{
if (hr < 10)
System.out.print("0");
System.out.print(hr + ":");
if (min < 10)
System.out.print("0");
System.out.print(min + ":");
if (sec < 10)
System.out.print("0");
System.out.print(sec);
}
//Method to increment the time by one second
//Postcondition: The time is incremented by one second
//If the before-increment time is 23:59:59, the time
//is reset to 00:00:00
public void incrementSeconds()
{
sec++;
if (sec > 59)
{
sec = 0;
incrementMinutes(); //increment minutes
}
}
//Method to increment the time by one minute
//Postcondition: The time is incremented by one minute
//If the before-increment time is 23:59:53, the time
//is reset to 00:00:53
public void incrementMinutes()
{
min++;
if (min > 59)
{
min = 0;
incrementHours(); //increment hours
}
}
//Method to increment the time by one hour
//Postcondition: The time is incremented by one hour
//If the before-increment time is 23:45:53, the time
//is reset to 00:45:53
public void incrementHours()
{
hr++;
if (hr > 23)
hr = 0;
}
//Method to compare two times
//Postcondition: Returns true if this time is equal to
// otherClock; otherwise returns false
public boolean equals(Clock otherClock)
{
return (hr == otherClock.hr
&& min == otherClock.min
&& sec == otherClock.sec);
}
//Method to copy time
//Postcondition: The instance variables of otherClock
// copied into the corresponding data
// are members of this time.
// hr = otherClock.hr;
// min = otherClock.min;
// sec = otherClock.sec;
public void makeCopy(Clock otherClock)
{
hr = otherClock.hr;
min = otherClock.min;
sec = otherClock.sec;
}
//Method to return a copy of time
//Postcondition: A copy of the object is created and
// a reference of the copy is returned
public Clock getCopy()
{
Clock temp = new Clock();
temp.hr = hr;
temp.min = min;
temp.sec = sec;
return temp;
}
}
//Program to test various operations of the class Clock
import java.util.*;
public class TestProgClock
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{
Clock myClock = new Clock(5, 4, 30); //Line 1
Clock yourClock = new Clock(); //Line 2
int hours; //Line 3
int minutes; //Line 4
int seconds; //Line 5
System.out.print("Line 6: myClock: "); //Line 6
myClock.printTime(); //Line 7
System.out.println(); //Line 8
System.out.print("Line 9: yourClock: "); //Line 9
yourClock.printTime(); //Line 10
System.out.println(); //Line 11
yourClock.setTime(5, 45, 16); //Line 12
System.out.print("Line 13: After setting "+ "the time - yourClock: "); //Line 13
yourClock.printTime(); //Line 14
System.out.println(); //Line 15
if (myClock.equals(yourClock)) //Line 16
System.out.println("Line 17: Both the " + "times are equal."); //Line 17
else //Line 18
System.out.println("Line 19: The two " + "times are not " + "equal."); //Line 19
System.out.print("Line 20: Enter hours, "+ "minutes, and seconds: "); //Line 20
hours = console.nextInt(); //Line 21
minutes = console.nextInt(); //Line 22
seconds = console.nextInt(); //Line 23
System.out.println(); //Line 24
myClock.setTime(hours, minutes, seconds); //Line 25
System.out.print("Line 26: New time of "+ "myClock: "); //Line 26
myClock.printTime(); //Line 27
System.out.println(); //Line 28
myClock.incrementSeconds(); //Line 29
System.out.print("Line 30: After "+ "incrementing the time by " + "one second, myClock: "); //Line 30
myClock.printTime(); //Line 31
System.out.println(); //Line 32
yourClock.makeCopy(myClock); //Line 33
System.out.print("Line 34: After copying "+ "myClock into yourClock, " + "yourClock: "); //Line 34
yourClock.printTime(); //Line 35
System.out.println(); //Line 36
}//end main
}
Sample Output:
Line 6: myClock: 05:04:30
Line 9: yourClock: 00:00:00
Line 13: After setting the time - yourClock: 05:45:16
Line 19: The two times are not equal.
Line 20: Enter hours, minutes, and seconds: 11 22 59
Line 26: New time of myClock: 11:22:59
Line 30: After incrementing the time by one second, myClock: 11:23:00
Line 34: After copying myClock into yourClock, yourClock: 11:23:00
Triangle of Stars - Void Method - Java Sample Program
// Program: Print a triangle of stars
// Given the number of lines, this program prints a triangle of stars.
import java.util.*;
public class TriangleOfStars
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{
int numberOfLines;
int numberOfBlanks;
int counter = 1;
System.out.print("Enter the number of star lines " + "(1 to 20) to be printed: ");
numberOfLines = console.nextInt();
System.out.println();
while (numberOfLines < 0 || numberOfLines > 20)
{
System.out.println("The number of star lines should " + "be between 1 and 20");
System.out.print("Enter the number of star lines " + "(1 to 20) to be printed: ");
numberOfLines = console.nextInt();
System.out.println ();
}
numberOfBlanks = 30;
for (counter = 1; counter <= numberOfLines; counter++)
{
printStars(numberOfBlanks, counter);
numberOfBlanks--;
}
} // end main
public static void printStars(int blanks, int starsInLine)
{
int count = 1;
for (count = 1; count <= blanks; count++)
System.out.print(" ");
for (count = 1; count <= starsInLine; count++)
System.out.print(" *");
System.out.println();
} //end printStars
}
Sample Output:
Enter the number of star lines (1 to 20) to be printed: 10
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
In the method main, the user is first asked to specify how many lines of stars to print. (In
this program, the user is restricted to 20 lines because a triangular grid of up to 20 lines fits
nicely on the screen.) Because the program is restricted to only 20 lines, the while loop
in the method main ensures that the program prints the triangular grid of stars only if the
number of lines is between 1 and 20.
// Given the number of lines, this program prints a triangle of stars.
import java.util.*;
public class TriangleOfStars
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{
int numberOfLines;
int numberOfBlanks;
int counter = 1;
System.out.print("Enter the number of star lines " + "(1 to 20) to be printed: ");
numberOfLines = console.nextInt();
System.out.println();
while (numberOfLines < 0 || numberOfLines > 20)
{
System.out.println("The number of star lines should " + "be between 1 and 20");
System.out.print("Enter the number of star lines " + "(1 to 20) to be printed: ");
numberOfLines = console.nextInt();
System.out.println ();
}
numberOfBlanks = 30;
for (counter = 1; counter <= numberOfLines; counter++)
{
printStars(numberOfBlanks, counter);
numberOfBlanks--;
}
} // end main
public static void printStars(int blanks, int starsInLine)
{
int count = 1;
for (count = 1; count <= blanks; count++)
System.out.print(" ");
for (count = 1; count <= starsInLine; count++)
System.out.print(" *");
System.out.println();
} //end printStars
}
Sample Output:
Enter the number of star lines (1 to 20) to be printed: 10
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
In the method main, the user is first asked to specify how many lines of stars to print. (In
this program, the user is restricted to 20 lines because a triangular grid of up to 20 lines fits
nicely on the screen.) Because the program is restricted to only 20 lines, the while loop
in the method main ensures that the program prints the triangular grid of stars only if the
number of lines is between 1 and 20.
Subscribe to:
Posts (Atom)