Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Ex02Butterfly {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine());
  7.  
  8.         int columns = 2 * n - 1;
  9.  
  10.         char[] oddLine = new char[columns];
  11.         char[] evenLine = new char[columns];
  12.         char[] centerLine = new char[columns];
  13.  
  14.         for (int i = 0; i < columns; i++) {
  15.             oddLine[i] = '*';
  16.             evenLine[i] = '-';
  17.             centerLine[i] = ' ';
  18.         }
  19.  
  20.         oddLine[n] = '/';
  21.         oddLine[n - 1] = ' ';
  22.         oddLine[n - 2] = '\\';
  23.         evenLine[n] = '/';
  24.         evenLine[n - 1] = ' ';
  25.         evenLine[n - 2] = '\\';
  26.         centerLine[n - 1] = '@';
  27.  
  28.         int rows = 2 * n - 3;
  29.         int center = rows / 2;
  30.  
  31.         for (int i = 0; i < rows; i++) {
  32.             if (i == center) {
  33.                 System.out.println(centerLine);
  34.                 oddLine[n] = '\\';
  35.                 oddLine[n - 2] = '/';
  36.                 evenLine[n] = '\\';
  37.                 evenLine[n - 2] = '/';
  38.             } else if (i % 2 == 0) {
  39.                 System.out.println(oddLine);
  40.             } else {
  41.                 System.out.println(evenLine);
  42.             }
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement