Program :
class Pattern
{
public static void main(String args[])
{
int r,c;
for(r=1;r<=11;r++)
{
if(r<=6)
{
for(c=r;c>=1;c--)
{
System.out.print(c+" ");
}
}
else
{
for(c=12-r;c>=1;c--)
{
System.out.print(c+" ");
}
}
System.out.println();
}
}
}
Output :
As given the pattern's sample output /structure in your question:
Program :
class Pattern
{
public static void main(String args[])
{
int r,c;
for(r=1;r<=11;r++)
{
if(r<=6)
{
for(c=r;c>=1;c--)
{
System.out.print(c+" ");
}
}
else if(r>6 && r<=9)
{
for(c=12-r;c>=1;c--)
{
System.out.print(c+" ");
}
}
System.out.println();
}
}
}
Output :
Note :
Both the programs are correct just I thought last 2 lines of your sample pattern were missing(intentionally or accidentally) so giving you two programs. first: may you wanted that way or second: you have given intentionally.
Get Answers For Free
Most questions answered within 1 hours.