Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- /*
- task 5
- problem 7
- */
- import java.util.Scanner;
- public class Main {
- public static final String INPUT_MESSAGE = "enter n:";
- public static final String FIRST_ERROR_MESSAGE = "input error";
- public static final String SECOND_ERROR_MESSAGE = "error: n is odd";
- public static int getInt(Scanner scanner){
- System.out.println(INPUT_MESSAGE);
- while(true){
- while(!scanner.hasNextInt()){
- System.out.println(FIRST_ERROR_MESSAGE);
- scanner.next();
- }
- int a = scanner.nextInt();
- if(a%2==1){
- return a;
- }
- else{
- System.out.println(SECOND_ERROR_MESSAGE);
- }
- }
- }
- public static void draw(int n, char bg, char fg){
- for(int i = 0; i < n/2; i++){
- for(int j = 0; j < (n-(1+2*i))/2; j++){
- System.out.print(bg);
- }
- for(int j = 0; j < 1+2*i;j++){
- System.out.print(fg);
- }
- for(int j = 0; j < (n-(1+2*i))/2; j++){
- System.out.print(bg);
- }
- System.out.println();
- }
- for(int j = 0; j < n;j++){
- System.out.print(fg);
- }
- System.out.println();
- for(int i = n/2-1; i >= 0; i--){
- for(int j = (n-(1+2*i))/2-1; j >= 0; j--){
- System.out.print(bg);
- }
- for(int j = 0; j < 1+2*i;j++){
- System.out.print(fg);
- }
- for(int j = (n-(1+2*i))/2-1; j >= 0; j--){
- System.out.print(bg);
- }
- System.out.println();
- }
- }
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = getInt(scanner);
- draw(n,'.','#');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement