import java.util.Scanner; /** * Prints filled and empty rectangles for a LED display */ class Solution { /** * Gets data from standard input */ private Scanner input; /** * Start the execution of the solution * @param args Command line arguments */ public static void main(String args[]) { Solution solution = new Solution(); solution.run(); } /** * Run the solution. This method is called from main() */ public void run() { // Create object to read data from standard input input = new Scanner(System.in); // try { // Read the width of the rectangle, stop if it is negative int width = input.nextInt(); if ( width < 0 ) throw new RuntimeException("invalid data"); // If there is another number int height = width; if ( input.hasNextInt() ) { // Read the height, stop if it is negative height = input.nextInt(); if ( height < 0 ) throw new RuntimeException("invalid data"); } // Read the fill character char fillChar = input.next().charAt(0); // Read the boolean that indicates if the rectangle is filled // We read the boolean as 0 or 1, and stop if something else is given int filled = input.nextInt(); if ( filled != 0 && filled != 1 ) throw new RuntimeException("invalid data"); boolean isFilled = filled == 1; // Print each of the height rows for ( int row = 1; row <= height; ++row ) { // Print each of the width columns in the row for ( int column = 1; column <= width; ++column ) { // If rectangle is filled, or row is first or last one, or column is first or last one if ( isFilled || row == 1 || row == height || column == 1 || column == width ) { // Print the fill character System.out.print(fillChar); } else { // Print a space System.out.print(' '); } } // Print a new line System.out.println(); } } catch ( java.util.InputMismatchException exception ) { System.out.println("invalid data"); } catch ( java.util.NoSuchElementException exception ) { System.out.println("missing data"); } catch ( RuntimeException exception ) { System.out.println( exception.getMessage() ); } // // Close the standard input input.close(); } }