Advertisement
AntonS2000

Untitled

Oct 30th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.42 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static final String INPUT_MESSAGE = "enter w:";
  8.     public static final String FIRST_ERROR_MESSAGE = "input error";
  9.  
  10.     public static int getInt(Scanner scanner){
  11.         while(true){
  12.             while(!scanner.hasNextInt()){
  13.                 System.out.println(FIRST_ERROR_MESSAGE);
  14.                 scanner.next();
  15.             }
  16.             int a = scanner.nextInt();
  17.  
  18.             if(a>=3 && a%2 == 1){
  19.                 return a;
  20.             }
  21.             else{
  22.                 System.out.println(FIRST_ERROR_MESSAGE);
  23.             }
  24.         }
  25.     }
  26.  
  27.  
  28.     public static void draw(int w){
  29.         //печатаем 1 строку
  30.         for(int i = 0; i < w; i++){
  31.             System.out.print("*");
  32.         }
  33.         System.out.println();
  34.  
  35.         for (int i = w/2; i >= 1; i--){
  36.  
  37.             for(int j = 0; j < i; j++){
  38.                 System.out.print("*");
  39.             }
  40.  
  41.             for(int j = 0; j < w-2*i; j++){
  42.                 System.out.print(" ");
  43.             }
  44.  
  45.             for(int j = 0; j < i; j++){
  46.                 System.out.print("*");
  47.             }
  48.             System.out.println();
  49.         }
  50.     }
  51.  
  52.     public static void main(String[] args) {
  53.         Scanner scanner = new Scanner(System.in);
  54.  
  55.         System.out.println(INPUT_MESSAGE);
  56.         int w = getInt(scanner);
  57.  
  58.         draw(w);
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement