thieumao

Source code cây thông

Dec 24th, 2013
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. // MERRY Christmas to all
  2.  
  3. public class XmasTree {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         int treeHeight = 11;
  8.         int stemHeight = 5;
  9.         int numberOfSpaces = treeHeight - 1;
  10.         int numberOfStars = 1;
  11.         for (int i = 0; i < treeHeight; i++) {
  12.             for (int j = 0; j < numberOfSpaces; j++) {
  13.                 System.out.print(" ");
  14.             }
  15.             for (int j = 0; j < numberOfStars; j++) {
  16.                 System.out.print("*");
  17.             }
  18.             numberOfSpaces--;
  19.             numberOfStars += 2;
  20.             System.out.println("");
  21.         }
  22.         numberOfSpaces = treeHeight - 2;
  23.         for (int i = 0; i < stemHeight; i++) {
  24.             for (int j = 0; j < numberOfSpaces; j++) {
  25.                 System.out.print(" ");
  26.             }
  27.             for (int j = 0; j < 3; j++) {
  28.                 System.out.print("*");
  29.             }
  30.             System.out.println("");
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment