Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PrintingLikeBoss {
- // copy or rewrite the method of Assignment 39.1 here
- public static void printStars(int amount) {
- int i = 0;
- while (i<amount) {
- System.out.print("*");
- i++;
- }
- System.out.println("");
- }
- public static void printWhitespaces(int amount) {
- int i = 0;
- while (i<amount) {
- System.out.print(" ");
- i++;
- }
- // 40.1
- }
- public static void printTriangle(int size) {
- int i = 0;
- while (i<size) {
- printWhitespaces(size-(i+1));
- printStars(i+1);
- i++;
- }// 40.2
- }
- public static void xmasTree(int height) {
- int i = 0;
- int stars = 1;
- while (i<height) {
- printWhitespaces(height-(i+1));
- printStars(stars);
- stars = stars + 2;
- i++;
- } // 40.3
- printWhitespaces(height-2);
- printStars(3);
- printWhitespaces(height-2);
- printStars(3);
- }
- public static void main(String[] args) {
- // Tests do not use main, yo can write code here freely!
- printTriangle(4);
- System.out.println("---");
- xmasTree(4);
- System.out.println("---");
- xmasTree(10);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement