Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- public static final String INPUT_MESSAGE = "enter w:";
- public static final String FIRST_ERROR_MESSAGE = "input error";
- public static int getInt(Scanner scanner){
- while(true){
- while(!scanner.hasNextInt()){
- System.out.println(FIRST_ERROR_MESSAGE);
- scanner.next();
- }
- int a = scanner.nextInt();
- if(a>=3 && a%2 == 1){
- return a;
- }
- else{
- System.out.println(FIRST_ERROR_MESSAGE);
- }
- }
- }
- public static void draw(int w){
- //печатаем 1 строку
- for(int i = 0; i < w; i++){
- System.out.print("*");
- }
- System.out.println();
- for (int i = w/2; i >= 1; i--){
- for(int j = 0; j < i; j++){
- System.out.print("*");
- }
- for(int j = 0; j < w-2*i; j++){
- System.out.print(" ");
- }
- for(int j = 0; j < i; j++){
- System.out.print("*");
- }
- System.out.println();
- }
- }
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- System.out.println(INPUT_MESSAGE);
- int w = getInt(scanner);
- draw(w);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement