Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static boolean flag = false;
- public static void tree(int limit ,int temp){
- for( int i = 2 ;i<limit-temp;i=i+2){
- for(int j=0;j<limit-i;j++){
- System.out.print(" ");
- }
- for(int k=0;k<=i;k++){
- System.out.print("* ");
- }
- System.out.println();
- }
- flag = false;
- }
- public static void main(String[] args) throws NumberFormatException, IOException {
- Scanner sc=new Scanner(System.in);
- System.out.println("Enter No of Days:");
- int days=sc.nextInt();
- boolean first = true;
- if(days<=1){
- System.out.println("You cannot generate christmas tree");
- return;
- }
- if(days>20){
- System.out.println("Tree is no more");
- return;
- }
- int n = days+1;
- int limit = n + n;
- int temp = 0;
- for(int i=1;i<=days+1;i++){
- tree(limit,temp);
- temp+=3;
- }
- for(int i=0;i<2;i++){
- for(int j=0;j<limit;j++){
- System.out.print(" ");
- }
- System.out.println("*");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement