Advertisement
paykova

p05_SquareFrame

Oct 19th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class p05_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. String firstAndLastLine = "+"
  10. + repeatStr(" -", n - 2)
  11. + " +";
  12. System.out.println(firstAndLastLine);
  13.  
  14. for (int i = 0; i <n-2 ; i++) {
  15. String loop = "|"
  16. + repeatStr(" -", n-2)
  17. + " |";
  18. System.out.println(loop);
  19. }
  20.  
  21. System.out.println(firstAndLastLine);
  22. }
  23.  
  24.  
  25.  
  26. static String repeatStr(String strToRepeat, int count) {
  27. String text = "";
  28. for (int i = 0; i < count; i++) {
  29. text += strToRepeat;
  30. }
  31. return text;
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement