TheBulgarianWolf

Christmas Hat Shape

Mar 23rd, 2020
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main
  3. {
  4.     public static void main(String[] args) {
  5.         Scanner sc = new Scanner(System.in);
  6.         System.out.print("Enter a number:");
  7.         int num = Integer.parseInt(sc.nextLine());
  8.         String dots = generateFrom(".",((4*num)-2)/2);
  9.         //top of the Christmas hat
  10.         System.out.println(dots + "/|\\" + dots);
  11.         System.out.println(dots + "\\|/" + dots);
  12.         //middle part of the hat - 2*num rows
  13.         int dotNum = ((4*num)-2)/2;
  14.         int dashNum = 0;
  15.         for(int i = 0;i<2*num;i++){
  16.             String insideDot = generateFrom(".",dotNum);
  17.             String dash = generateFrom("-",dashNum);
  18.             System.out.println(insideDot + "*" + dash + "*" + dash + "*" + insideDot);
  19.             dotNum--;
  20.             dashNum++;
  21.         }
  22.         //last part of the hat
  23.         String stars = generateFrom("*",4*num+1);
  24.         System.out.println(stars);
  25.         for(int h = 0;h<4*num+1;h++){
  26.             if(h % 2 == 0){
  27.                 System.out.print("*");
  28.             }
  29.             else{
  30.                 System.out.print(".");
  31.             }
  32.         }
  33.         System.out.println();
  34.         System.out.println(stars);
  35.     }
  36.    
  37.     static String generateFrom(String symbol,int number){
  38.         String text = "";
  39.         for(int i=0;i<number;i++){
  40.             text += symbol;
  41.         }
  42.        
  43.         return text;
  44.     }
  45. }
Add Comment
Please, Sign In to add comment