Advertisement
tchenkov

L06u12_Butterfly

Feb 16th, 2017
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.77 KB | None | 0 0
  1. package Uprajneniq;
  2.  
  3. import java.text.MessageFormat;
  4. import java.util.Scanner;
  5.  
  6. /**
  7.  * Created by todor on 16.02.2017 г..
  8.  */
  9. public class u12_Butterfly {
  10.     public static void main(String[] args) {
  11.         Scanner scan = new Scanner(System.in);
  12.         int butterflySizeIndex = Integer.parseInt(scan.nextLine());
  13.         int wingsHeight = butterflySizeIndex - 2;
  14.        
  15.         String starString = stringRepeater("*", wingsHeight);
  16.         String wingOfStarsTop = MessageFormat.format("{0}\\ /{0}", starString);
  17.         String wingOfDashesTop = wingOfStarsTop.replace('*','-');
  18.         String wingOfStarsBottom = MessageFormat.format("{0}/ \\{0}", starString);
  19.         String wingOfDashesBottom = wingOfStarsBottom.replace('*','-');
  20.         String butterflyBody = stringRepeater(" ", wingsHeight +1) + "@";
  21.        
  22.         boolean printStars = true;
  23.         butterflyWingsOutput(wingsHeight, wingOfDashesTop, wingOfStarsTop, printStars);
  24.         System.out.println(butterflyBody);
  25.         butterflyWingsOutput(wingsHeight, wingOfDashesBottom, wingOfStarsBottom, printStars);
  26.     }
  27.    
  28.     public static void butterflyWingsOutput(int wingsHeight, String wingOfDashesTop, String wingOfStarsBottom, boolean printStars) {
  29.         for (int i = 0; i < wingsHeight; i++, printStars = !printStars) {
  30.             if (printStars){
  31.                 System.out.println(wingOfStarsBottom);
  32.             }
  33.             else {
  34.                 System.out.println(wingOfDashesTop);
  35.             }
  36.         }
  37.     }
  38.    
  39.     static String stringRepeater (String stringToRepeat, int stringRepeatCount){
  40.         String outputString = "";
  41.         for (int i = 0; i < stringRepeatCount; i++) {
  42.             outputString += stringToRepeat;
  43.         }
  44.         return outputString;
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement