https://i2.wp.com/eblogarithm.com/wp-content/uploads/2016/10/Drawing-A-Hollow-Rectangle-Using-Java1.png?fit=640%2C360

Drawing A Hollow Rectangle Using Java

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(“”);
}
}
}

(Visited 127 times, 1 visits today)



There are no comments

Add yours

Leave a Reply

%d bloggers like this: