Advertisement
korobushk

Untitled

Feb 25th, 2020
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. public class AdvancedAstrology {
  2.  
  3. public static void printStars(int number) {
  4. int beginning = 0;
  5.  
  6. while (beginning < number) {
  7. System.out.print("*");
  8. beginning++;
  9. }
  10. System.out.println("");
  11. // part 1 of the exercise
  12. }
  13.  
  14. public static void printSpaces(int number) {
  15. int beginning = 0;
  16.  
  17. while (beginning < number) {
  18. System.out.print(" ");
  19. beginning++;
  20. }
  21.  
  22. // part 1 of the exercise
  23. }
  24.  
  25. public static void printTriangle(int size) {
  26. int i = 1;
  27.  
  28. while (i <= size) {
  29. printSpaces(size - i);
  30. printStars(i);
  31.  
  32. i++;
  33.  
  34. }
  35. }
  36.  
  37. public static void christmasTree(int height) {
  38. int i = 1;
  39. int h = 1;
  40. int j = 1;
  41.  
  42. while (i <= height) {
  43.  
  44. printSpaces(height - i);
  45. printStars(h);
  46.  
  47. i++;// part 3 of the exercise
  48. h = h + 2;
  49.  
  50. }
  51.  
  52. printSpaces(height - 2);
  53. printStars(3);
  54. printSpaces(height - 2);
  55. printStars(3);
  56.  
  57. }
  58.  
  59. public static void main(String[] args) {
  60. // The tests are not checking the main, so you can modify it freely.
  61.  
  62. printTriangle(3);
  63. System.out.println("---");
  64. christmasTree(4);
  65. System.out.println("---");
  66. christmasTree(10);
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement