ChrismasTree.java - package week3 The purpose of this...

This preview shows page 1 - 2 out of 2 pages.

package week3;/* The purpose of this assignment is to make a tree and than through the useparameters to resize it. */public class ChrismasTree {public static void main(String[] args) {makeTree(3, 4);makeTree(2, 5);}// makeTree method that codes the tree we will print //// two int variables Segments and Height//public static void makeTree(int Segments, int Height) {// equation to calculate how man asterisks to put in each line//int Asterisks = 1 + 2 * (Segments - 1) + 2 * (Height - 1);// string variable that will change through out//String maxStr = "";// used to generate needed spaces //for (int i = 0; i < Asterisks; i++) {maxStr += " ";}// segment loop//for (int i = 1; i <= Segments; i++) {// puts in proper amount of asterisks as (Asterisks) loop through// each line//for (int j = 1; j <= Height; j++) {String asteriskStr = "";for (int k = 1; k <= 2 * j + 2 * i - 3; k++) {

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture