Drawing A Hollow Rectangle Using Java

0
274
Sponsors

hello people, here is easy code for drawing a hollow rectangle using java. this code displays a rectangle of given length and width.
Sample input:
4
5
Sample output
*****
*      *
*      *
*****

import java.util.Scanner;
public class hollowRectangle{
public static void main(String args[]){
Scanner anik = new Scanner(System.in);
System.out.println(“give a row number”);
int rnum = anik.nextInt();
System.out.println(“give a coloum number”);
int cnum = anik.nextInt();
for(int count = 1; count <= rnum; ++count){
if(count ==1 || count == rnum){
for(int xcount = 1; xcount <= cnum; ++xcount){
System.out.print(“*”);
}
}else{
for(int ycount = 1; ycount <= cnum; ++ycount){
if(ycount ==1 || ycount == cnum){
System.out.print(“*”);
}else{
System.out.print(” “);
}
}

}
System.out.println(“”);
}
}
}

Sponsors

LEAVE A REPLY

Please enter your comment!
Please enter your name here