Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void printStars(int number) {
- for (int i = 0; i < number; i++) {
- System.out.print("*");
- }
- System.out.println(" ");
- }
- public static void printSpaces(int number) {
- for (int i = 0; i < number; i++) {
- System.out.print(" ");
- }
- }
- public static void printTriangle(int number) {
- // Each row of Triangles are made up of stars and spaces
- // may be I should count their numbers and come up with general
- // formula that satisfies the condition at each row.
- for (int i = 0; i < number; i++) {
- // how many spaces do I need at each line?
- // for the first row I would need 4 spaces
- // for the second row I would need 3 spaces
- // for the third row I would need 2 spaces
- // for the fourth row I would need 1 space.
- // for the fifth row I would need 0 spaces
- printSpaces(number - i - 1);
- // how many starts do I need at each line?
- // for the first row I would need 1 star
- // for the second row I would need 2 stars
- // for the third row I would need 3 stars
- // for the fourth row I would need 4 stars
- // for the fifth row I would need 5 stars.
- printStars(i + 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement