</> ᴍᴜᴋᴇsʜ </>
Print Hollow Rectangle Pattern using java .
public class Hollowrect {
public static void HollowrectPattern(int noOfRows, int noOfCols) {
// for rows outer loop
for (int i = 1; i <= noOfRows; i++) {
// inner loop
for (int j = 1; j <= noOfCols; j++) {
// cell (i,j)
if (i == 1 || i == noOfRows || j == 1 || j == noOfCols) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}
public static void main(String[] args) {
HollowrectPattern(4, 7);
}
}
OutPut:
*******
* *
* *
*******
5 · 1.7K ·