Advertisement
kimh_greenhill

Programming Project 1_Chapter 3

Jan 26th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. /**
  2. * Programming Project 1 Chapter 3
  3. *
  4. * Hannah Kim
  5. * January 21, 2015
  6. */
  7. public class ProgrammingProject1
  8. {
  9. public static void main (String [] args)
  10. {
  11. int lines = 3;
  12. int segments = 4;
  13. tree(lines,segments);
  14. base(lines, segments);
  15. }
  16. public static void tree(int lines, int segments)
  17. {
  18. int maxspace = lines + segments - 1;
  19. for (int i = 1; i <= segments; i++)
  20. {
  21. for (int j = 1; j <= i + lines - 1; j++)
  22. {
  23. for (int spaces = 1; spaces <= maxspace - j; spaces++)
  24. {
  25. System.out.print(" ");
  26. }
  27. for (int stars = 1; stars <= 2 * j - 1; stars++)
  28. {
  29. System.out.print("*");
  30. }
  31. System.out.println();
  32. }
  33. }
  34. }
  35. public static void base(int lines, int segments)
  36. {
  37. int maxspace = lines + segments - 2 ;
  38. for (int i = 1; i <= 2; i++)
  39. {
  40. for (int j = 1; j <= maxspace; j++)
  41. {
  42. System.out.print(" ");
  43. }
  44. System.out.println("*");
  45. }
  46. for (int base = 1; base <= lines + segments - 5; base++)
  47. {
  48. System.out.print(" ");
  49. }
  50. System.out.print("*******");
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement