Java program to print rectangle of stars

Java program to print rectangle of stars

Java program to print a particular pattern of stars or numbers is one of the commonly asked Java interview questions. Writing Java programs to print certain pattern will also help you in mastering nested loops and recursion in Java. There are many pattern based programs and one of them is printing rectangular structure. In this post we will write Java program to print rectangle of stars.

Below is the rectangle pattern to print using Java.

Rectangle Pattern Java

To build the above pattern we need two inputs. 1. number of columns and 2. number of rows.

Here is the Java program to print the above rectangle pattern of stars.

Here is the output of the above program.

Here is another simple rectangle pattern.

Rectangle Pattern in Java

Below is the Java program to print the above pattern.

Below is a sample output of the above program.

The logic is pretty straightforward, so I believe I don’t need to explain it. You can try the same program with difference approach like using recursion etc.

That’s all about Java program to print rectangle pattern of stars.

Also read,

Java program to print pyramid pattern

The following two tabs change content below.
Working as a Java developer since 2010. Passionate about programming in Java. I am a part time blogger.
One comment

Add Comment

Required fields are marked *. Your email address will not be published.