skipter icon

Square Frame N x N - Drawing with Loops

skipter | PRO | 04/13/17 11:23:02 AM UTC | 0 ⭐ | 367 👁️ | Never ⏰ | []
Java |

830 B

|

None

|

0 👍

/

0 👎

import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
 
        int number = Math.abs(Integer.parseInt(input.nextLine()));
 
        for (int row = 0; row < 1 ; row++) {
                System.out.println("+ " + repeatStr("- ", number - 2) + "+");
            for (int col = 1; col <= number - 2 ; col++) {
                System.out.println("| " + repeatStr("- ", number - 2) + "|");
            }
             System.out.println("+ " + repeatStr("- ", number - 2) + "+");
        }
    }
 
    public static String repeatStr(String str, int count) {
        StringBuilder squareFlame = new StringBuilder();
 
        for (int i = 0; i < count; i++) {
            squareFlame.append(str);
        }
        return squareFlame.toString();
    }
}

Comments