Muhaiminur
2/12/2018 - 7:50 PM

Hollow Rectangle Star

Hollow Rectangle Display a rectangle of given length and width. Sample input: 4 5 Sample output



Hint 1: Print the character space (‘ ‘) in the middle. Hint 2: You can re-use your solution to PROBLEM 2 and use if condition to selectively print first and last star of each line and all stars of first and last line.

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package BASICJAVA;

import java.util.Scanner;

/**
 *
 * @author ABIR
 */
public class Hollow_Rectangle_Star {
    public static void main(String[]args){
        Scanner abir=new Scanner(System.in);
        System.out.println("Enter sample input");
        int x=abir.nextInt();
        int y=abir.nextInt();
        System.out.println("sample output");
        int d=0;
        while(d<y){
          System.out.print("*");
          d++;
        }
        System.out.println();
        int e=0;
        while(e<x-2){
          System.out.print("*");
          int f=0;
          while(f<y-2){
            System.out.print(" ");
            f++;
            }
          System.out.print("*");
          System.out.println();
          e++;
          }
          int g=0;
          while(g<y){
            System.out.print("*");
            g++;
          }
          System.out.println();
          System.out.println("=======================================================");
      }
}