Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Using loops and control statements to draw lines

1. ## Using loops and control statements to draw lines

hey all...i have a homework and really i don't know how to solve this questions ...this is a period of exams and i don't have enough time to do alot of homeworks..please help me..

Q1) Using loops and control statements to draw lines can lead to many interesting designs.
a) Create the design in the left screen capture of Fig. 4.21. This design draws lines from
the top-left corner, fanning out the lines until they cover the upper-left half of the panel.
One approach is to divide the width and height into an equal number of steps (we found
15 steps worked well). The first endpoint of a line will always be in the top-left corner
(0, 0). The second endpoint can be found by starting at the bottom-left corner and
moving up one vertical step and right one horizontal step. Draw a line between the two
endpoints. Continue moving up and to the right one step to find each successive end-
point. The figure should scale accordingly as you resize the window.
b) Modify your answer in part (a) to have lines fan out from all four corners, as shown in
the right screen capture of Fig. 4.21. Lines from opposite corners should intersect along
the middle.

4.2 Figure 4.22 displays two additional designs created using while loops and drawLine.
a) Create the design in the left screen capture of Fig. 4.22. Begin by dividing each edge
into an equal number of increments (we chose 15 again). The first line starts in the top-
left corner and ends one step right on the bottom edge. For each successive line, move
down one increment on the left edge and right one increment on the bottom edge. Con-
tinue drawing lines until you reach the bottom-right corner. The figure should scale as
you resize the window so that the endpoints always touch the edges.
right screen capture of Fig. 4.22.

2. ## Re: Using loops and control statements to draw lines

...edited by moderator

3. ## Re: Using loops and control statements to draw lines

@hbaysal
What is the purpose of the code you posted?
You have not explained why you have coded it the way that you have.

Spoonfeeding answers to OPs is discouraged.

Whoops, missed the age of this thread!!!

@hbaysal,