Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. public class PrintingLikeBoss {
  2.  
  3. // copy or rewrite the method of Assignment 39.1 here
  4. public static void printStars(int amount) {
  5.  
  6. int i = 0;
  7.  
  8. while (i<amount) {
  9. System.out.print("*");
  10. i++;
  11. }
  12. System.out.println("");
  13. }
  14.  
  15. public static void printWhitespaces(int amount) {
  16.  
  17.  
  18. int i = 0;
  19.  
  20. while (i<amount) {
  21.  
  22. System.out.print(" ");
  23. i++;
  24. }
  25. // 40.1
  26. }
  27.  
  28. public static void printTriangle(int size) {
  29.  
  30. int i = 0;
  31.  
  32. while (i<size) {
  33.  
  34. printWhitespaces(size-(i+1));
  35. printStars(i+1);
  36.  
  37. i++;
  38.  
  39. }// 40.2
  40.  
  41. }
  42.  
  43. public static void xmasTree(int height) {
  44.  
  45. int i = 0;
  46. int stars = 1;
  47.  
  48. while (i<height) {
  49.  
  50. printWhitespaces(height-(i+1));
  51. printStars(stars);
  52.  
  53. stars = stars + 2;
  54. i++;
  55. } // 40.3
  56. printWhitespaces(height-2);
  57. printStars(3);
  58. printWhitespaces(height-2);
  59. printStars(3);
  60.  
  61. }
  62.  
  63. public static void main(String[] args) {
  64. // Tests do not use main, yo can write code here freely!
  65.  
  66. printTriangle(4);
  67. System.out.println("---");
  68. xmasTree(4);
  69. System.out.println("---");
  70. xmasTree(10);
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement