Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.sample;
- import static java.lang.System.out;
- public class ChristmasTree1 {
- public static void main(String[] args) {
- printTriangle(4, 2);
- printTriangle(4, 3);
- printTriangle(4, 4);
- printTrunk(4, 2);
- }
- private static void printTrunk(int width, int height) {
- width = width - 1;
- for (int i = 1; i <= height; i++) {
- for (int j = 1; j <= width; j++) {
- out.print(" ");
- }
- out.print("*");
- out.println();
- }
- }
- private static void printTriangle(int width, int height) {
- for (int i = 1; i <= height; i++) {
- for (int j = 1; j <= (width - i); j++) {
- out.print(" ");
- }
- for (int j = 1; j <= (2 * i) - 1; j++) {
- out.print("*");
- }
- out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement