Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DrawTriangles
- {
- private int stars, lines, spaces;
- // This method draws the first triangle
- public void drawTriangle1(int choice)
- {
- for (lines = 1; lines <= choice; lines++)
- {
- for (stars = 1; stars <= lines; stars++)
- {
- System.out.print('*');
- System.out.print(' ');
- } // end inner loop
- System.out.println();
- } // end outer loop
- System.out.println();
- } // end drawTriangle1
- // This method draws the second triangle
- public void drawTriangle2(int choice)
- {
- for (lines = choice; lines >= 1; lines--)
- {
- for (stars = 1; stars <= lines; stars++)
- {
- System.out.print('*');
- System.out.print(' ');
- } // end inner loop
- System.out.println();
- }
- System.out.println();
- } // end drawTriangle2
- // This method draws the third triangle
- public void drawTriangle3(int choice)
- {
- for (lines = 1; lines <= choice; lines++)
- {
- for (spaces = choice; spaces > lines; spaces--)
- {
- System.out.print(' ');
- }
- for (stars = 1; stars <= lines; stars++)
- {
- System.out.print('*');
- } // end inner loop
- System.out.println();
- } // end outer loop
- System.out.println();
- }
- // This method draws the fourth triangle
- public void drawTriangle4(int choice)
- {
- for (lines = 1; lines <= choice; lines++)
- {
- for (spaces = 1; spaces <= lines; spaces++) // spaces loop is the same for both 3 and
- {
- System.out.print(' ');
- } // end inner loop
- for (stars = choice; stars >= lines; stars--)
- {
- System.out.print('*');
- }
- System.out.println();
- }
- System.out.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement