Ques - Write a java program for the following pattern of 'H' :
*. *
* *
* *
*****
* *
* *
* *
PROGRAM :
import java.util.Scanner;
class PatternH
{
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the number of rows : ");
int i, j, n;
int r=sc.nextInt();
int c=r-2;
if(r%2!=0)
{
n=r/2;
}
else
{
n=(r/2)-1;
}
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if((j==0)||(j==(c-1)))
{
System.out.print("*");
}
else if(i==n)
{
System.out.print("*");
}
else
{
System.out.print(" ");
}
}
System.out.println();
}
}
}
/* Output :
Enter the number of rows : 7
* *
* *
* *
*****
* *
* *
* *
*/