Q:

Java program to print a rectangle using stars (java pattern program)

0

Java program to print a rectangle using stars (java pattern program)

This program will be used to print a star pattern that will generate a rectangle.

Example:

*******
*     *
*     *
*     *
*     *
*     *
*******

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program to print rentable using stars in java

public class Pattern9 
{
	public static void main(String[] args) 
	{
		int number = 7;

		for (int i = 0; i < number; i++) 
		{
			if (i == 0 || i == 6) 
			{
				for (int j = 0; j < number; j++) 
				{
					System.out.print("*");
				}
				System.out.println();
			}
			if (i >= 1 && i <= 5) 
			{
				for (int j = 0; j < number; j++) 
				{
					if (j == 0 || j == 6) 
					{
						System.out.print("*");
					} 
					else if (j >= 1 && j <= 5) 
					{
						System.out.print(" ");
					}
				}
				System.out.println();
			}
		}
	}
}

Output

*******
*     *
*     *
*     *
*     *
*     *
*******

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now