Advertisement
Guest User

Untitled

a guest
Jul 30th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. public static boolean flag = false;
  2.  
  3. public static void tree(int limit ,int temp){
  4.  
  5. for( int i = 2 ;i<limit-temp;i=i+2){
  6.  
  7. for(int j=0;j<limit-i;j++){
  8. System.out.print(" ");
  9. }
  10. for(int k=0;k<=i;k++){
  11. System.out.print("* ");
  12.  
  13. }
  14.  
  15. System.out.println();
  16. }
  17. flag = false;
  18. }
  19. public static void main(String[] args) throws NumberFormatException, IOException {
  20. Scanner sc=new Scanner(System.in);
  21.  
  22. System.out.println("Enter No of Days:");
  23.  
  24. int days=sc.nextInt();
  25.  
  26. boolean first = true;
  27.  
  28. if(days<=1){
  29. System.out.println("You cannot generate christmas tree");
  30. return;
  31. }
  32.  
  33. if(days>20){
  34. System.out.println("Tree is no more");
  35. return;
  36.  
  37. }
  38.  
  39. int n = days+1;
  40. int limit = n + n;
  41. int temp = 0;
  42. for(int i=1;i<=days+1;i++){
  43.  
  44. tree(limit,temp);
  45. temp+=3;
  46. }
  47. for(int i=0;i<2;i++){
  48. for(int j=0;j<limit;j++){
  49. System.out.print(" ");
  50. }
  51. System.out.println("*");
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement