Advertisement
tchenkov

L06u05_SquareFrame

Feb 16th, 2017
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 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 15.02.2017 г..
  8.  */
  9. public class u05_SquareFrame {
  10.     public static void main(String[] args) {
  11.         Scanner scan = new Scanner(System.in);
  12.         int squareFrameSize = Integer.parseInt(scan.nextLine());
  13.         int frameFilamentSize = squareFrameSize - 2;
  14.    
  15.         String frameCorner = "+ ";
  16.         String frameLeftRightSide = "| ";
  17.         String frameFilament = "- ";
  18.        
  19.         String frameTopBottomString = stringFormatter(frameCorner, frameFilament, frameFilamentSize);
  20.         String frameMiddleString = stringFormatter(frameLeftRightSide, frameFilament, frameFilamentSize);
  21.    
  22.         System.out.println(frameTopBottomString);
  23.    
  24.         for (int i = 0; i < frameFilamentSize; i++) {
  25.             System.out.println(frameMiddleString);
  26.         }
  27.    
  28.         System.out.println(frameTopBottomString);
  29.     }
  30.    
  31.     static String stringRepeater (String stringToRepeat, int stringRepeatCount){
  32.         String outputString = "";
  33.         for (int i = 0; i < stringRepeatCount; i++) {
  34.             outputString += stringToRepeat;
  35.         }
  36.         return outputString;
  37.     }
  38.    
  39.     static String stringFormatter(String startEndString, String middleString, int middleRepeatCount){
  40.         return MessageFormat.format("{0}{1}{0}", startEndString, stringRepeater(middleString, middleRepeatCount));
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement