Sat Jun 20, 2009 10:01 am
^
20+
|
|
|
|
15+
|
|
|
|
10+
|
|
|
|
5+
|
|
|
|
+----+----+----+----+----+----+----+----+>
0 5 10 15 20 25 30 35 40
Upper Left: (5,10) Width: 8, Height: 4
********
********
********
EDIT: noticed the horizontal and vertical numbers are off on the forum here, but fine in program console.
/program START
//create class for filename
public class DrawRectangle
{
//create main arugment to show string text
public static void main(String[] args)
{
//temporarly hard code values.
int height = 4;
int width = 8;
int x = 5;
int y = 10;
//draw the whole graph and rectangle
System.out.println("\n\n ^");
//draw the verticle axis
for (int m = 20; m > 0; m--)
{
if (m == 5)
System.out.println(" " + m + "+");
else if (m % 5 == 0)
System.out.println(m + "+");
else
System.out.println(" |");
}
System.out.print(" ");
//draw the horizontal axis
for (int n = 0; n <= 40; n++)
{
if (n % 5 == 0)
System.out.print("+");
else
System.out.print("-");
}
System.out.print(">");
System.out.println();
//create numbers for the horizontal axis
for (int p = 0; p <= 40; p++)
{
if (p % 5 == 0)
System.out.print(" " + p);
}
//draw the description
System.out.println("\n\n Upper Left: (" + x + "," + y + ") Width: " + width + ", Height: " + height + "\n\n");
[color=#FF0000]//printing the rectangle
for (int hcount = 1; hcount <= height; hcount++)
{
System.out.println("");
for(int wcount = 1; wcount <= width; wcount++)
System.out.print("*");
}[/color]
} // main method end brace.
} // drawrectangle class end brace
//program END
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.