martinvalchev

Square Frame

Nov 11th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SquareFrame {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int n = Integer.parseInt(scanner.nextLine());
  8.  
  9.         // First row
  10.             System.out.print("+");
  11.             for (int symbol = 0; symbol < n -2  ; symbol++) {
  12.                 System.out.print(" -");
  13.  
  14.             }
  15.             System.out.print(" +");
  16.  
  17.             // Middle part
  18.         System.out.println();
  19.         for (int row = 0; row < n -2  ; row++) {
  20.             System.out.print("|");
  21.             for (int symbol = 0; symbol < n -2  ; symbol++) {
  22.                 System.out.print(" -");
  23.         }
  24.             System.out.println(" |");
  25.  
  26.         }
  27.         System.out.print("+");
  28.         for (int symbol = 0; symbol < n -2  ; symbol++) {
  29.             System.out.print(" -");
  30.  
  31.         }
  32.         System.out.print(" +");
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment