Hollow Rectangle Pattern
import java.util.*;
public class pattern {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.println("Enter The Matrix Size in the format of columns and rows");
int row=s.nextInt();
int col=s.nextInt();
for(int i=1;i<=row;i++){
for(int j=1;j<=col;j++){
if(i==1||j==col||i==row||j==1)
System.out.print('*');
else{
System.out.print(" ");
}
}
System.out.print("\n");
}
// char k='A';
// for(int j=1;j<5;j++){
// for(int i=1;i<=j;i++){
// System.out.print(k);
// k++;
// }
// System.out.print("\n");
// }
}
}
Output:-
Comments
Post a Comment