Print a hollow rectangle star with the help of nested loop
Vaishnavi Shrivastava
1 min read
Table of contents
import java.util.Scanner;
/**
* Link4
*/
public class Link {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("enter a number");
int n = sc.nextInt();
System.out.println("enter a number");
int m = sc.nextInt();
for (int i = 1; i <= n; i++) { //for outer loops , rows
for (int j = 1; j <=m; j++) { // for inner loops , columns
if(i==1 || j==1 || i==n|| j==m){
System.out.print("*");
}
else{
System.out.print( " ");
}
}
System.out.println();
}
}
}
0
Subscribe to my newsletter
Read articles from Vaishnavi Shrivastava directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by