In this program, a pattern
as shown below will be printed using the nested loop program.
The pattern is:
1
!
12
!
123
!
1234
!
class Pat
{
int i,j,x=1;
public void show()
{
for(i=1;i<=8;i++)
{
if(i%2==0)
{
System.out.println("!");
x++;
continue;
}
for(j=1;j<=x;j++)
{
System.out.print(j);
}
System.out.println();
}
}
public static void
main(String args[]) throws Exception
{
Pat ob=new Pat();
ob.show();
}
No comments:
Post a Comment