icse-promo

Question

Design a class to overload a function polygon() as follows:
(i) void polygon(int n, char ch) : with one integer argument and one character type argument that draws a filled square of side n using the character stored in ch.
(ii) void polygon(int x, int y) : with two integer arguments that draws a filled rectangle of length x and breadth y, using the symbol ‘@’
(iii)void polygon( ) : with no argument that draws a filled triangle shown below.

				
					Example:
(i) Input value of n=2, ch=’O’
Output:
O O
O O
(ii) Input value of x=2, y=5
Output:
@ @ @ @ @
@ @ @ @ @
(iii) Output:
*
* *
* * *
				
			

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					public class program7
{
	public void polygon(int n, char ch)
	{
	    int i=0,j=0;
		for (i = 1; i <= n; i++)
		{
			for (j = 1; j <= n; j++)
			{
				System.out.print(ch);
			}
			System.out.println();
		}
	}
	public void polygon(int x, int y)
	{
	    int i=0,j=0;
		for (i = 1; i <= x; i++)
		{
			for (j = 1; j <= y; j++)
			{
				System.out.print("@");
			}
			System.out.println();
		}
	}
	public void polygon()
	{
	    int i=0,j=0;
		for (i = 1; i <= 3; i++)
		{
			for (j = 1; j <= i; j++)
			{
				System.out.print("*");
			}
			System.out.println();
		}
	}
}

				
			

Coding Store

Leave a Reply

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