Advertisement
skipter

Square Frame N x N - Drawing with Loops

Apr 13th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner input = new Scanner(System.in);
  7.  
  8.         int number = Math.abs(Integer.parseInt(input.nextLine()));
  9.  
  10.         for (int row = 0; row < 1 ; row++) {
  11.                 System.out.println("+ " + repeatStr("- ", number - 2) + "+");
  12.             for (int col = 1; col <= number - 2 ; col++) {
  13.                 System.out.println("| " + repeatStr("- ", number - 2) + "|");
  14.             }
  15.              System.out.println("+ " + repeatStr("- ", number - 2) + "+");
  16.         }
  17.     }
  18.  
  19.     public static String repeatStr(String str, int count) {
  20.         StringBuilder squareFlame = new StringBuilder();
  21.  
  22.         for (int i = 0; i < count; i++) {
  23.             squareFlame.append(str);
  24.         }
  25.         return squareFlame.toString();
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement