BubaLazi

p06_Rectangle*

Mar 11th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.lang.String;
  3.  
  4. public class AdvancedLoops {
  5.     public static void main(String[] args) {
  6.         Scanner console = new Scanner(System.in);
  7.  
  8.         int n = Integer.parseInt(console.nextLine());
  9.  
  10.         System.out.printf("%s\n", repeatStr("*", n));
  11.         for (int i = 0; i < n ; i++) {
  12.  
  13.             for (int row = 0; row < i - 2; row++) {
  14.                 System.out.printf("%s%s%s", repeatStr("*", 1),
  15.                                             repeatStr(" ", n-2),
  16.                                             repeatStr("*", 1));
  17.                 System.out.println();
  18.  
  19.             }
  20.         }
  21.         System.out.printf("%s\n", repeatStr("*", n));
  22.  
  23.  
  24.  
  25.     }
  26.     static String repeatStr(String strToRepeat, int count) {
  27.       String text = "";
  28.  
  29.         for (int i = 0; i < count; i++) {
  30.             text = text + strToRepeat;
  31.         }
  32.  
  33.         return text;
  34.     }
  35.  
  36. }
Add Comment
Please, Sign In to add comment