borkins

Exam 26-Mar-2016 - 05. Butterfly

May 14th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.52 KB | None | 0 0
  1. /**
  2.  * Project: Exam_26_March_2016 - created by borkins on 2017-05-14.
  3.  */
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class _05_Butterfly
  8. {
  9.     public static void main(String[] args)
  10.     {
  11.         Scanner console = new Scanner(System.in);
  12.    
  13.         int n = Integer.parseInt(console.nextLine());
  14.    
  15.         int rows = 2 * (n - 2) + 1;
  16.    
  17.         String stars = new String(new char[n - 2]).replace("\0", "*");
  18.         String dashes = new String(new char[n - 2]).replace("\0", "-");
  19.         String wingsOfStars = stars + "\\ " + "/" + stars;
  20.         String wingsOfDashes = dashes + "\\ " + "/" + dashes;
  21.    
  22.         for (int row = 0; row < rows; row++)
  23.         {
  24.             if (row == rows / 2)
  25.             {
  26.                 for (int col = 0; col < n - 1; col++) {
  27.                     System.out.print(" ");
  28.                 }
  29.                 System.out.println("@");
  30.                 continue;
  31.             }
  32.        
  33.             if (row % 2 == 0)
  34.             {
  35.                 if (row < rows / 2) {
  36.                     System.out.println(wingsOfStars);
  37.                 }
  38.                 else {
  39.                     System.out.println(new StringBuilder(wingsOfStars).reverse());
  40.                 }
  41.             }
  42.             else
  43.             {
  44.                 if (row < rows / 2) {
  45.                     System.out.println(wingsOfDashes);
  46.                 }
  47.                 else {
  48.                     System.out.println(new StringBuilder(wingsOfDashes).reverse());
  49.                 }
  50.             }
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment