Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Pr10DiamondNoMethod {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine());
  7.  
  8.         int lines = n;
  9.         int dashes = n / 2;
  10.         int middleLine = n / 2;
  11.  
  12.         if (n % 2 == 0) {
  13.             lines--;
  14.             dashes--;
  15.             middleLine--;
  16.         }
  17.  
  18.         String headerFooterLine = new String(new char[dashes]).replace("\0", "-") +
  19.                 new String(new char[2 - n % 2]).replace("\0", "*") +
  20.                 new String(new char[dashes]).replace("\0", "-");
  21.  
  22.         for (int i = 0; i < lines; i++) {
  23.             if (i == 0 || i == lines - 1) {
  24.                 System.out.println(headerFooterLine);
  25.             } else {
  26.                 System.out.println(new String(new char[dashes]).replace("\0", "-") + "*" +
  27.                         new String(new char[n - 2 - dashes * 2]).replace("\0", "-") + "*" +
  28.                         new String(new char[dashes]).replace("\0", "-"));
  29.             }
  30.  
  31.             if (i < middleLine) {
  32.                 dashes--;
  33.             } else {
  34.                 dashes++;
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement