   import java.util.Scanner;
/*
*Assignment 1, Prints out an octagon.
*
*@author [Student Name]
*
*/
   public class Program5{
   
      public static void main(String[] args){
         Scanner scan = new Scanner(System.in);
      
         System.out.println("This program draws an octagon.");
      
         int value = 0;
         boolean isValid = false;
/*
*Uses a try catch in a while loop to see if the input is a valid integer
*/      
         while(!isValid){
            System.out.println("Please enter a size as ean integer (1-12): ");
            try{
               value = scan.nextInt();
            
               if(value <= 12 && value >=1){
                  isValid = true;
               }
               else{
                  System.out.println("Sorry, the size must be between 1-12. Try again.");
               }
            }
               catch(Exception e){
                  System.out.println("Sorry, but that is not an integer. Try again.");
                  scan.nextLine();
               }
         }
/*
*Uses a nested for loop with an if statement to show went to print spaces and then prints the # for everywhere else.
*/     
         for(int row = 0; row < value*3; row++){
            for(int col = 0; col < value*3; col++){
               if((col < value && ((row+col)<value)) || ((col > value*2-1 && ((col-row) > value*2-1))) || ((row > value*2-1 && ((row-col) > value*2-1))) || (row > value*2-1 && ((col+row) >= value*5-1))){
                  System.out.print(" ");
               }
               else{
                  System.out.print("#");
               }
            }
            System.out.print("\n");
         }
      }
   }
   