Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Project: Exam_101_January_2016 - created by borkins on 2017-05-03.
- */
- import java.util.Scanner;
- public class _10_RectangleWithStars
- {
- public static void main(String[] args)
- {
- Scanner console = new Scanner(System.in);
- int n = Integer.parseInt(console.nextLine());
- int rows = n + ((n % 2 == 0) ? 1 : 2);
- int cols = n * 2;
- int innerSp = (n * 2) - 2;
- int centerSp = (innerSp / 2) - 1;
- for (int i = 1; i <= rows; i++)
- {
- if (i == 1 || i == rows) {
- System.out.println(newString("%", cols));
- continue;
- }
- System.out.print("%");
- if (i != (rows - (rows / 2))) {
- System.out.print(newString(" ", innerSp));
- }
- else {
- System.out.printf("%s**%s",
- newString(" ", centerSp),
- newString(" ", centerSp));
- }
- System.out.println("%");
- }
- }
- public static String newString(String str, int count)
- {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < count; i++) {
- sb.append(str);
- }
- return sb.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment