Advertisement
16120

Butterfly

May 8th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class butfly {
  4.  
  5.     static String repeatStr(String strToRepeat, int count) {
  6.         String text = "";
  7.         for (int i = 0; i < count; i++) {
  8.             text += strToRepeat;
  9.         }
  10.         return text;
  11.     }
  12.  
  13.     public static void main(String[] args) {
  14.         Scanner sc = new Scanner(System.in);
  15.         int n = Integer.parseInt(sc.nextLine());
  16.         int halfRowSize = n - 2;
  17.  
  18.         for (int i = 1; i <= halfRowSize; i++) {
  19.             if (i % 2 != 0) {
  20.                 System.out.println(String.format("%s\\ /%s", repeatStr("*", halfRowSize), repeatStr("*", halfRowSize)));
  21.             } else {
  22.                 System.out.println(String.format("%s\\ /%s", repeatStr("-", halfRowSize), repeatStr("-", halfRowSize)));
  23.             }
  24.         }
  25.         System.out.println(String.format("%s @ %s", repeatStr(" ", halfRowSize), repeatStr(" ", halfRowSize)));
  26.  
  27.         for (int i = 1; i <= halfRowSize; i++) {
  28.             if (i % 2 != 0) {
  29.                 System.out.println(String.format("%s/ \\%s", repeatStr("*", halfRowSize), repeatStr("*", halfRowSize)));
  30.             } else {
  31.                 System.out.println(String.format("%s/ \\%s", repeatStr("-", halfRowSize), repeatStr("-", halfRowSize)));
  32.             }
  33.         }
  34.     }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement